亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? chatclient2.cs

?? 100個(gè)非常有趣的C語言UNIX程序?qū)嵗???梢栽跇啡ぶ芯毩?xí)C語言編程。
?? CS
字號(hào):
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net.Sockets;
using System.IO;
using System.Threading;
using System.Text;

namespace ChatClient
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class ChatClientForm : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TextBox ChatOut;
		private System.Windows.Forms.StatusBar statusBar1;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.Button btnConnect;
		private System.Windows.Forms.Button btnSend;
		private int serverport;
		private NetworkStream ns;
		private StreamReader sr;
		private TcpClient clientsocket;
		private Thread receive = null;
		private string serveraddress;
		private System.Windows.Forms.ListBox lbChatters;
		private System.Windows.Forms.RichTextBox rtbChatIn;
		private System.Windows.Forms.Button btnDisconnect;
		private string clientname;
		//private string destclient;
		private bool connected = false;
		private bool logging = false;
		private bool privatemode = false;
		private System.Windows.Forms.Button btnLog;
		private System.Windows.Forms.CheckBox cbPrivate;
		private StreamWriter logwriter;


		public ChatClientForm()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			serverport = 5555;
			btnDisconnect.Enabled = false;
			btnSend.Enabled = false;

		}

		/// <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.cbPrivate = new System.Windows.Forms.CheckBox();
			this.btnLog = new System.Windows.Forms.Button();
			this.btnSend = new System.Windows.Forms.Button();
			this.lbChatters = new System.Windows.Forms.ListBox();
			this.ChatOut = new System.Windows.Forms.TextBox();
			this.btnConnect = new System.Windows.Forms.Button();
			this.rtbChatIn = new System.Windows.Forms.RichTextBox();
			this.statusBar1 = new System.Windows.Forms.StatusBar();
			this.btnDisconnect = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// cbPrivate
			// 
			this.cbPrivate.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.cbPrivate.Location = new System.Drawing.Point(384, 112);
			this.cbPrivate.Name = "cbPrivate";
			this.cbPrivate.Size = new System.Drawing.Size(64, 24);
			this.cbPrivate.TabIndex = 10;
			this.cbPrivate.Text = "Private";
			this.cbPrivate.CheckStateChanged += new System.EventHandler(this.cbPrivate_CheckedChanged);
			// 
			// btnLog
			// 
			this.btnLog.Location = new System.Drawing.Point(376, 80);
			this.btnLog.Name = "btnLog";
			this.btnLog.Size = new System.Drawing.Size(80, 24);
			this.btnLog.TabIndex = 9;
			this.btnLog.Text = "Start Logging";
			this.btnLog.Click += new System.EventHandler(this.btnLog_Click);
			// 
			// btnSend
			// 
			this.btnSend.Location = new System.Drawing.Point(264, 232);
			this.btnSend.Name = "btnSend";
			this.btnSend.Size = new System.Drawing.Size(64, 24);
			this.btnSend.TabIndex = 5;
			this.btnSend.Text = "Send";
			this.btnSend.Click += new System.EventHandler(this.btnSend_Click);
			// 
			// lbChatters
			// 
			this.lbChatters.Location = new System.Drawing.Point(272, 16);
			this.lbChatters.Name = "lbChatters";
			this.lbChatters.SelectionMode = System.Windows.Forms.SelectionMode.None;
			this.lbChatters.Size = new System.Drawing.Size(88, 212);
			this.lbChatters.TabIndex = 7;
			// 
			// ChatOut
			// 
			this.ChatOut.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.ChatOut.Location = new System.Drawing.Point(8, 232);
			this.ChatOut.Name = "ChatOut";
			this.ChatOut.Size = new System.Drawing.Size(240, 23);
			this.ChatOut.TabIndex = 2;
			this.ChatOut.Text = "";
			this.ChatOut.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.ChatOut_KeyPress);
			// 
			// btnConnect
			// 
			this.btnConnect.Location = new System.Drawing.Point(376, 16);
			this.btnConnect.Name = "btnConnect";
			this.btnConnect.Size = new System.Drawing.Size(80, 24);
			this.btnConnect.TabIndex = 4;
			this.btnConnect.Text = "Connect";
			this.btnConnect.Click += new System.EventHandler(this.btnConnect_Click);
			// 
			// rtbChatIn
			// 
			this.rtbChatIn.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.rtbChatIn.Location = new System.Drawing.Point(8, 16);
			this.rtbChatIn.Name = "rtbChatIn";
			this.rtbChatIn.ReadOnly = true;
			this.rtbChatIn.Size = new System.Drawing.Size(240, 212);
			this.rtbChatIn.TabIndex = 6;
			this.rtbChatIn.Text = "";
			// 
			// statusBar1
			// 
			this.statusBar1.Location = new System.Drawing.Point(0, 275);
			this.statusBar1.Name = "statusBar1";
			this.statusBar1.Size = new System.Drawing.Size(478, 16);
			this.statusBar1.SizingGrip = false;
			this.statusBar1.TabIndex = 3;
			this.statusBar1.Text = "Disconnected";
			// 
			// btnDisconnect
			// 
			this.btnDisconnect.Location = new System.Drawing.Point(376, 48);
			this.btnDisconnect.Name = "btnDisconnect";
			this.btnDisconnect.Size = new System.Drawing.Size(80, 24);
			this.btnDisconnect.TabIndex = 8;
			this.btnDisconnect.Text = "Disconnect";
			this.btnDisconnect.Click += new System.EventHandler(this.btnDisconnect_Click);
			// 
			// ChatClientForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(478, 291);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.cbPrivate,
																		  this.btnLog,
																		  this.btnDisconnect,
																		  this.lbChatters,
																		  this.rtbChatIn,
																		  this.btnSend,
																		  this.btnConnect,
																		  this.statusBar1,
																		  this.ChatOut});
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
			this.Name = "ChatClientForm";
			this.Text = "ChatClient";
			this.ResumeLayout(false);

		}
		#endregion
		protected override void OnClosed(EventArgs e)
		{
			QuitChat();
			if(receive != null && receive.IsAlive)
				receive.Abort();
			
			base.OnClosed(e);
		}

		private void EstablishConnection()
		{
			statusBar1.Text = "Connecting to Server";
			try 
			{
				clientsocket = new TcpClient(serveraddress,serverport);
				ns = clientsocket.GetStream();
				sr = new StreamReader(ns);
				connected = true;
			}
			catch (Exception e)
			{
				MessageBox.Show("Could not connect to Server","Error",
					MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				statusBar1.Text = "Disconnected";
			}
		}
		private void RegisterWithServer()
		{
			try 
			{
				string command = "CONN|" + ChatOut.Text;
				Byte[] outbytes = System.Text.Encoding.ASCII.GetBytes(command.ToCharArray());
				ns.Write(outbytes,0,outbytes.Length);
				
				string serverresponse = sr.ReadLine();
				serverresponse.Trim();
				string[] tokens = serverresponse.Split(new Char[]{'|'});
				if(tokens[0] == "LIST")
				{
					statusBar1.Text = "Connected";
					btnDisconnect.Enabled = true;
				}
				for(int n=1; n<tokens.Length-1; n++)
					lbChatters.Items.Add(tokens[n].Trim(new char[]{'\r','\n'}));
				this.Text = clientname + ": Connected to Chat Server";
				
			}
			catch (Exception e)
			{
				MessageBox.Show("Error Registering","Error",
					MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
			}
		}
		
		private void ReceiveChat()
		{
			bool keepalive = true;
			while (keepalive) 
			{
				try
				{
					Byte[] buffer = new Byte[2048];
					ns.Read(buffer,0,buffer.Length);
					string chatter = System.Text.Encoding.ASCII.GetString(buffer);

					string[] tokens = chatter.Split(new Char[]{'|'});

					if (tokens[0] == "CHAT")
					{
						rtbChatIn.AppendText(tokens[1]);
						if(logging)
							logwriter.WriteLine(tokens[1]);
					}
					if (tokens[0] == "PRIV") {
						rtbChatIn.AppendText("Private from ");
						rtbChatIn.AppendText(tokens[1].Trim() );
						rtbChatIn.AppendText(tokens[2] + "\r\n");
						if(logging){
							logwriter.Write("Private from ");
							logwriter.Write(tokens[1].Trim() );
							logwriter.WriteLine(tokens[2] + "\r\n");
						}
					}
					if (tokens[0] == "JOIN")
					{
						rtbChatIn.AppendText(tokens[1].Trim() );
						rtbChatIn.AppendText(" has joined the Chat\r\n");
						if(logging){
							logwriter.WriteLine(tokens[1]+" has joined the Chat");
						}
						string newguy = tokens[1].Trim(new char[]{'\r','\n'});
						lbChatters.Items.Add(newguy);
					}
					if (tokens[0] == "GONE")
					{
						rtbChatIn.AppendText(tokens[1].Trim() );
						rtbChatIn.AppendText(" has left the Chat\r\n");
						if(logging){
							logwriter.WriteLine(tokens[1]+" has left the Chat");
						}
						lbChatters.Items.Remove(tokens[1].Trim(new char[]{'\r','\n'}));
					}
					if (tokens[0] == "QUIT")
					{
						ns.Close();
						clientsocket.Close();
						keepalive = false;
						statusBar1.Text = "Server has stopped";
						connected= false;
						btnSend.Enabled = false;
						btnDisconnect.Enabled = false;
					}
				}
				catch(Exception e){}
			}
		}
		private void QuitChat() 
		{
			if(connected) {
				try{
					string command = "GONE|" + clientname;
					Byte[] outbytes = System.Text.Encoding.ASCII.GetBytes(command.ToCharArray());
					ns.Write(outbytes,0,outbytes.Length);
					clientsocket.Close();
				}
				catch(Exception ex){
				}
			}
			if(logging)
				logwriter.Close();

			if(receive != null && receive.IsAlive)
				receive.Abort();
			this.Text = "ChatClient";
			
		}
		private void StartStopLogging() 
		{
			if(!logging){
				if(!Directory.Exists("logs"))
					Directory.CreateDirectory("logs");
				string fname = "logs\\" + DateTime.Now.ToString("ddMMyyHHmm") + ".txt";
				logwriter = new StreamWriter(new FileStream(fname, FileMode.OpenOrCreate,
					FileAccess.Write));
				logging = true;
				btnLog.Text = "Stop Logging";
				statusBar1.Text = "Connected - Log on";
			}
			else{
				logwriter.Close();
				logging = false;
				btnLog.Text = "Start Logging";
				statusBar1.Text = "Connected - Log off";
			}

		}
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main(String[] args) 
		{
			ChatClientForm cf = new ChatClientForm();
			if(args.Length == 0)
				cf.serveraddress = "localhost";
			else
				cf.serveraddress = args[0];

			Application.Run(cf);
		}

		private void btnConnect_Click(object sender, System.EventArgs e)
		{
			if(ChatOut.Text == ""){
				MessageBox.Show("Enter a name in the box before connecting","Error",
					MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				return;
			}
			else
				clientname = ChatOut.Text;
			
			EstablishConnection();
			
			if(connected)
			{
				RegisterWithServer();
				receive = new Thread(new ThreadStart(ReceiveChat));
				receive.Start();
				btnSend.Enabled = true;
				btnConnect.Enabled = false;
				ChatOut.Text = "";
			}
		}

		private void btnSend_Click(object sender, System.EventArgs e)
		{
			try{
				string dclient = "";
				if(!privatemode){
					string pubcommand = "CHAT|" + clientname +": "+ChatOut.Text + "\r\n";
					Byte[] outbytes = System.Text.Encoding.ASCII.GetBytes(pubcommand.ToCharArray());
					ns.Write(outbytes,0,outbytes.Length);
					ChatOut.Text = "";
				}
				else{
					if(lbChatters.SelectedIndex == -1){
						MessageBox.Show("Select a chatter name from the list","Error",
							MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
						return;
					}

					string destclient = lbChatters.SelectedItem.ToString();
					string command = "PRIV|" + clientname + "|: " + ChatOut.Text + "|" + destclient;
					Byte[] outbytes = System.Text.Encoding.ASCII.GetBytes(command.ToCharArray());
					ns.Write(outbytes,0,outbytes.Length);
					ChatOut.Text = "";
				}

			}
			catch(Exception ex){
				MessageBox.Show("Connection with Server lost","Error",
					MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				ns.Close();
				clientsocket.Close();
				if(receive != null && receive.IsAlive)
					receive.Abort();
				connected = false;
				statusBar1.Text = "Disconnected";
			}
		}

		private void btnDisconnect_Click(object sender, System.EventArgs e)
		{
			QuitChat();
			btnDisconnect.Enabled = false;
			btnConnect.Enabled = true;
			btnSend.Enabled = false;
			ns.Close();
			clientsocket.Close();
			receive.Abort();
			connected = false;
			lbChatters.Items.Clear();
			statusBar1.Text = "Disconnected";
		}

		private void ChatOut_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) {
			if(e.KeyChar == '\r')
				if(connected)
					btnSend_Click(sender, e);
				else
					btnConnect_Click(sender, e);
		}

		private void btnLog_Click(object sender, System.EventArgs e) {
			StartStopLogging();
		}

		private void cbPrivate_CheckedChanged(object sender, System.EventArgs e) {
			if(cbPrivate.Checked){
				privatemode = true;
				lbChatters.SelectionMode = System.Windows.Forms.SelectionMode.One;
			}
			else{
				privatemode = false;
				lbChatters.SelectionMode = System.Windows.Forms.SelectionMode.None;
			}
		}

	}
}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久久国产精品不卡| 蜜桃一区二区三区在线观看| 国产精品狼人久久影院观看方式| 精品久久久久久久久久久久久久久| 56国语精品自产拍在线观看| 正在播放一区二区| 欧美久久一二区| 欧美一区二区美女| 日韩欧美一区二区三区在线| 国产亚洲视频系列| 久久精品日产第一区二区三区高清版| 欧美草草影院在线视频| 精品国产一区二区亚洲人成毛片| 欧美一区二区三区视频免费播放| 欧美一区二区视频免费观看| 日韩午夜av一区| ww久久中文字幕| 国产欧美一区二区三区在线老狼| 一色桃子久久精品亚洲| 亚洲精品中文在线观看| 亚洲国产成人porn| 蜜臀99久久精品久久久久久软件| 国产在线日韩欧美| av亚洲精华国产精华精华| 99久久精品国产一区二区三区| 一本久久a久久免费精品不卡| 欧洲激情一区二区| 在线综合+亚洲+欧美中文字幕| 欧美电视剧免费观看| 中文字幕欧美国产| 一区二区三区毛片| 免费三级欧美电影| 成人性色生活片免费看爆迷你毛片| 成人性视频网站| 欧美性xxxxxx少妇| 日韩女优av电影| 中文字幕第一区二区| 亚洲一区二区三区国产| 日本中文字幕不卡| 国产很黄免费观看久久| 91精品福利在线| 亚洲精品一区二区三区香蕉| 国产精品乱码一区二区三区软件 | 成人高清免费观看| 色综合欧美在线视频区| 欧美一区二区三区视频免费| 国产欧美精品区一区二区三区 | 一区二区三区 在线观看视频| 日韩av在线播放中文字幕| 在线综合+亚洲+欧美中文字幕| 精品欧美一区二区三区精品久久| 国产精品天干天干在线综合| 日韩vs国产vs欧美| 成人avav影音| 欧美电影免费观看高清完整版在| 成人欧美一区二区三区1314| 奇米精品一区二区三区在线观看 | 7777女厕盗摄久久久| 中国av一区二区三区| 日韩电影一区二区三区| 成人亚洲一区二区一| 欧美一区二区三区人| 亚洲欧美日韩在线| 久久99国产精品麻豆| 欧美主播一区二区三区美女| 欧美高清在线一区二区| 久久精品国产99久久6| 一道本成人在线| 中文字幕免费一区| 精品在线观看视频| 欧美日韩一区二区三区四区五区| 国产婷婷精品av在线| 日韩专区一卡二卡| 日本高清免费不卡视频| 欧美极品美女视频| 美女在线视频一区| 9191成人精品久久| 一区二区在线观看免费视频播放| 高清在线观看日韩| 精品99久久久久久| 男人的天堂久久精品| 欧美亚洲动漫制服丝袜| 国产精品国产a| 国产ts人妖一区二区| 久久精品亚洲一区二区三区浴池| 免费日韩伦理电影| 欧美一级欧美三级| 亚洲国产精品人人做人人爽| 91香蕉视频在线| 国产精品毛片久久久久久久| 国产.精品.日韩.另类.中文.在线.播放| 91精品国产综合久久久久久久| 亚洲一区在线观看网站| 日本道在线观看一区二区| 中文字幕在线不卡视频| 成人小视频在线| 国产视频一区二区三区在线观看| 久久www免费人成看片高清| 欧美一区二区视频观看视频| 亚洲bt欧美bt精品777| 欧美日韩一区高清| 性欧美疯狂xxxxbbbb| 欧美日本在线看| 亚洲成人av一区二区| 777奇米四色成人影色区| 午夜精品久久久久影视| 欧美日韩中文字幕一区| 日韩激情av在线| 51午夜精品国产| 免费欧美日韩国产三级电影| 日韩一区二区三区观看| 玖玖九九国产精品| 精品对白一区国产伦| 国产精品一区2区| 国产精品乱码一区二区三区软件 | 精品动漫一区二区三区在线观看| 琪琪久久久久日韩精品| 久久综合色婷婷| 成人网在线免费视频| 亚洲日本成人在线观看| 91国内精品野花午夜精品| 亚洲成av人片在线观看| 欧美一级爆毛片| 国产精品主播直播| 亚洲天堂精品在线观看| 欧美影院精品一区| 人人超碰91尤物精品国产| 欧美刺激脚交jootjob| 成人视屏免费看| 一区二区三区视频在线看| 91精品国产一区二区三区香蕉| 激情都市一区二区| 成人免费在线视频观看| 欧美肥妇毛茸茸| 国产高清久久久| 亚洲精品久久7777| 欧美成人一区二区三区片免费 | 久久夜色精品一区| 99久久99久久精品免费看蜜桃| 亚洲成年人影院| 久久免费看少妇高潮| 91影院在线观看| 蜜乳av一区二区| 亚洲日本青草视频在线怡红院| 欧美日韩午夜影院| 国产美女在线观看一区| 亚洲精品美腿丝袜| 精品成人在线观看| 色综合久久天天综合网| 九九精品一区二区| 亚洲欧美日韩久久| 精品不卡在线视频| 欧美色中文字幕| 国产激情一区二区三区四区| 亚洲国产人成综合网站| 国产三级精品视频| 欧美高清视频不卡网| 成人一区二区三区| 男女男精品视频网| 亚洲精品欧美综合四区| 久久综合久久综合久久| 欧美在线观看一区| 高清av一区二区| 美女视频一区在线观看| 一区二区三区四区五区视频在线观看| 精品少妇一区二区三区视频免付费| 91啦中文在线观看| 国产精品99久久久久久似苏梦涵 | 日本在线不卡一区| 国产精品进线69影院| 精品国产百合女同互慰| 欧美综合亚洲图片综合区| 成人黄色网址在线观看| 麻豆国产精品777777在线| 亚洲午夜久久久久久久久久久| 国产丝袜美腿一区二区三区| 日韩亚洲国产中文字幕欧美| 一本色道综合亚洲| www.亚洲国产| 国产成人在线视频免费播放| 日本va欧美va欧美va精品| 一区二区三区中文字幕在线观看| 国产精品嫩草影院av蜜臀| 久久综合久久综合久久| 欧美成人精精品一区二区频| 欧美日韩国产成人在线免费| 色8久久精品久久久久久蜜| 成人免费视频播放| 国产资源精品在线观看| 美日韩一级片在线观看| 日本最新不卡在线| 午夜精品久久久久久久| 亚洲一区视频在线| 亚洲黄色小视频| 亚洲桃色在线一区| 中文字幕在线观看不卡视频| 国产精品嫩草影院com| 日韩高清在线一区| 亚洲国产sm捆绑调教视频| 洋洋av久久久久久久一区|