Click here to Skip to main content
15,895,781 members
Articles / Programming Languages / C#

Protocol implementation

Rate me:
Please Sign up or sign in to vote.
2.96/5 (9 votes)
31 Jan 20053 min read 35K   254   24  
Add some protocol support to your server.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text;
using Infinity.Networking;

namespace Server
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class frmServer : System.Windows.Forms.Form
	{
		private MultiThreadedServerBase  _server;

		private System.Windows.Forms.Button btnStart;
		private System.Windows.Forms.TextBox txtData;
		private System.Windows.Forms.Button btnStop;
		private System.Windows.Forms.Button button1;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmServer()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			_server = new INPServer("127.0.0.1",11000);
			
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.btnStart = new System.Windows.Forms.Button();
			this.txtData = new System.Windows.Forms.TextBox();
			this.btnStop = new System.Windows.Forms.Button();
			this.button1 = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// btnStart
			// 
			this.btnStart.Location = new System.Drawing.Point(352, 16);
			this.btnStart.Name = "btnStart";
			this.btnStart.TabIndex = 0;
			this.btnStart.Text = "Start";
			this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
			// 
			// txtData
			// 
			this.txtData.Location = new System.Drawing.Point(8, 16);
			this.txtData.Multiline = true;
			this.txtData.Name = "txtData";
			this.txtData.Size = new System.Drawing.Size(336, 88);
			this.txtData.TabIndex = 1;
			this.txtData.Text = "";
			// 
			// btnStop
			// 
			this.btnStop.Location = new System.Drawing.Point(352, 48);
			this.btnStop.Name = "btnStop";
			this.btnStop.TabIndex = 2;
			this.btnStop.Text = "Pause";
			this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(352, 80);
			this.button1.Name = "button1";
			this.button1.TabIndex = 3;
			this.button1.Text = "Resume";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// frmServer
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(432, 116);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.btnStop);
			this.Controls.Add(this.txtData);
			this.Controls.Add(this.btnStart);
			this.Name = "frmServer";
			this.Text = "Server";
			this.Closed += new System.EventHandler(this.frmServer_Closed);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new frmServer());
		}

		
		private void btnStart_Click(object sender, System.EventArgs e)
		{
			_server.Start();
			txtData.Text+=" server started.\r\n";
		}

		private void frmServer_Closed(object sender, System.EventArgs e)
		{
			_server.Stop();
		}

		private void btnStop_Click(object sender, System.EventArgs e)
		{
			_server.Suspend();
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			_server.Resume();
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Belgium Belgium
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions