Click here to Skip to main content
15,894,017 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 Infinity.Networking;

namespace Client
{
	/// <summary>
	/// Summary description for frmClient.
	/// </summary>
	public class frmClient : System.Windows.Forms.Form
	{
		private INPClient _client;
		private System.Windows.Forms.Button btnConnect;
		private System.Windows.Forms.RichTextBox log;
		private System.Windows.Forms.Button btnSend;
		private System.Windows.Forms.ComboBox cmbData;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

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

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

			_client = new INPClient("127.0.0.1",11000);
			_client.Log+=new Infinity.Networking.INPClient.LogHandler(_client_Log);
		
		}

		/// <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.btnConnect = new System.Windows.Forms.Button();
			this.log = new System.Windows.Forms.RichTextBox();
			this.btnSend = new System.Windows.Forms.Button();
			this.cmbData = new System.Windows.Forms.ComboBox();
			this.SuspendLayout();
			// 
			// btnConnect
			// 
			this.btnConnect.Location = new System.Drawing.Point(488, 64);
			this.btnConnect.Name = "btnConnect";
			this.btnConnect.TabIndex = 0;
			this.btnConnect.Text = "Connect";
			this.btnConnect.Click += new System.EventHandler(this.btnConnect_Click);
			// 
			// log
			// 
			this.log.Location = new System.Drawing.Point(8, 64);
			this.log.Name = "log";
			this.log.Size = new System.Drawing.Size(472, 360);
			this.log.TabIndex = 1;
			this.log.Text = "";
			// 
			// btnSend
			// 
			this.btnSend.Location = new System.Drawing.Point(488, 24);
			this.btnSend.Name = "btnSend";
			this.btnSend.TabIndex = 2;
			this.btnSend.Text = "Send";
			this.btnSend.Click += new System.EventHandler(this.btnSend_Click);
			// 
			// cmbData
			// 
			this.cmbData.Items.AddRange(new object[] {
														 "VER",
														 "DOUBLE",
														 "DIV",
														 "RES"});
			this.cmbData.Location = new System.Drawing.Point(8, 24);
			this.cmbData.Name = "cmbData";
			this.cmbData.Size = new System.Drawing.Size(472, 21);
			this.cmbData.TabIndex = 4;
			this.cmbData.Text = "VER";
			// 
			// frmClient
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(576, 436);
			this.Controls.Add(this.cmbData);
			this.Controls.Add(this.btnSend);
			this.Controls.Add(this.log);
			this.Controls.Add(this.btnConnect);
			this.Name = "frmClient";
			this.Text = "frmClient";
			this.ResumeLayout(false);

		}
		#endregion

		private void btnConnect_Click(object sender, System.EventArgs e)
		{
			_client.Connect();
		}

		private void btnSend_Click(object sender, System.EventArgs e)
		{
			if (cmbData.Text != "")
			{
				btnSend.Enabled = false;
				_client.Send(cmbData.Text);
				_client.WaitForData();
			}
		}

		private void _client_Log(object sender, LogEventArgs la)
		{
			log.AppendText("\n" + la.LogText);

			btnSend.Enabled = true;
		}
	}
}

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