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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? chatclient.cs

?? 100個非常有趣的C語言UNIX程序實例。可以在樂趣中練習C語言編程。
?? CS
字號:
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 bool connected = false;
		private bool logging = false;
		private System.Windows.Forms.Button btnLog;
		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.btnLog = new System.Windows.Forms.Button();
			this.rtbChatIn = new System.Windows.Forms.RichTextBox();
			this.btnSend = new System.Windows.Forms.Button();
			this.ChatOut = new System.Windows.Forms.TextBox();
			this.btnConnect = new System.Windows.Forms.Button();
			this.lbChatters = new System.Windows.Forms.ListBox();
			this.statusBar1 = new System.Windows.Forms.StatusBar();
			this.btnDisconnect = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// 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);
			// 
			// 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 = "";
			// 
			// 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);
			// 
			// 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);
			// 
			// 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;
			// 
			// statusBar1
			// 
			this.statusBar1.Location = new System.Drawing.Point(0, 277);
			this.statusBar1.Name = "statusBar1";
			this.statusBar1.Size = new System.Drawing.Size(480, 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(480, 293);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  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] == "JOIN")
					{
						rtbChatIn.AppendText(tokens[1].Trim() );
						rtbChatIn.AppendText(" has joined the Chat\r\n");
						if(logging){
							logwriter.Write(tokens[1]);
							logwriter.WriteLine(" has joined the Chat");
						}
						//string newguy = tokens[1].Trim(new char[]{'\r','\n'});
						lbChatters.Items.Add(tokens[1].Trim(new char[]{'\r','\n'}));
					}
					if (tokens[0] == "GONE")
					{
						rtbChatIn.AppendText(tokens[1].Trim() );
						rtbChatIn.AppendText(" has left the Chat\r\n");
						if(logging){
							logwriter.Write(tokens[1]);
							logwriter.WriteLine(" 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)
		{
			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 pubcommand = "CHAT|" + clientname +": "+ChatOut.Text + "\r\n";
				Byte[] outbytes = System.Text.Encoding.ASCII.GetBytes(pubcommand.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";
			rtbChatIn.Text = "";
		}

		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();
		}

	}
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
av一区二区三区黑人| 日韩va欧美va亚洲va久久| 九九久久精品视频| 欧洲中文字幕精品| 欧美经典一区二区| 美女网站在线免费欧美精品| 成人精品一区二区三区中文字幕| 欧美日韩二区三区| 亚洲综合色视频| 成人黄色小视频| 久久精品免费在线观看| 日韩**一区毛片| 欧美日韩国产高清一区二区| 亚洲欧美精品午睡沙发| 不卡av电影在线播放| 久久久影视传媒| 国产一区二区三区免费| 精品美女被调教视频大全网站| 日日摸夜夜添夜夜添国产精品| 欧美日韩综合一区| 国产精品超碰97尤物18| 99精品视频在线免费观看| 国产精品久久福利| 国产成人精品免费网站| 欧美国产国产综合| 91麻豆国产精品久久| 久久久精品人体av艺术| 激情久久五月天| 中文字幕欧美一| 色综合天天综合网国产成人综合天| 精品国产乱子伦一区| 国产精品一区二区不卡| 亚洲色图丝袜美腿| 欧美日韩国产首页在线观看| 免费高清不卡av| 国产欧美日韩精品在线| 在线视频中文字幕一区二区| 蜜臀久久99精品久久久久久9| 26uuu成人网一区二区三区| 国产成人啪午夜精品网站男同| 亚洲视频在线观看一区| 日韩精品中文字幕一区二区三区| 国产精品影视在线观看| 国产精品久久久久久福利一牛影视| 在线欧美一区二区| 国产精品一区三区| 亚洲线精品一区二区三区| 久久久噜噜噜久久中文字幕色伊伊| 99精品国产91久久久久久| 美洲天堂一区二卡三卡四卡视频 | 一区二区三区 在线观看视频| 91精品在线一区二区| 成人aaaa免费全部观看| 久久精品国产99| 亚洲国产日韩一区二区| 中文字幕免费一区| 日韩精品专区在线影院重磅| 99精品视频中文字幕| 亚洲欧美国产三级| 中文字幕在线免费不卡| 精品女同一区二区| 69久久夜色精品国产69蝌蚪网| www..com久久爱| 国产成人精品www牛牛影视| 日韩精品乱码免费| 国产精品久久夜| 久久精品水蜜桃av综合天堂| 欧美xxxxxxxx| 日韩欧美电影在线| 日韩视频一区二区三区在线播放| 在线免费观看日韩欧美| 91免费精品国自产拍在线不卡| 国产乱码一区二区三区| 久久福利视频一区二区| 久久9热精品视频| 久久精品噜噜噜成人88aⅴ| 免费观看成人av| 久久99精品国产麻豆婷婷洗澡| 亚洲在线观看免费视频| 天天操天天综合网| 免费成人在线视频观看| 精品制服美女丁香| 亚洲电影第三页| 欧美激情艳妇裸体舞| 久久亚洲精品小早川怜子| 欧美日韩激情在线| 岛国精品在线播放| 99久久久久免费精品国产 | 福利一区二区在线| 成人性视频免费网站| 成人ar影院免费观看视频| 成人福利电影精品一区二区在线观看| 全部av―极品视觉盛宴亚洲| 秋霞电影网一区二区| 国产综合色视频| 成人视屏免费看| 欧洲生活片亚洲生活在线观看| 欧美日韩一级黄| 精品国产第一区二区三区观看体验| 欧美日韩亚洲另类| 久久久久久**毛片大全| 中文字幕在线一区二区三区| 亚洲高清三级视频| 精一区二区三区| 91在线porny国产在线看| 精品视频在线看| 欧美韩日一区二区三区四区| 亚洲国产一区二区三区青草影视| 一区二区三区中文字幕在线观看| 日韩激情视频网站| 福利电影一区二区| 91精品国产福利在线观看| 久久无码av三级| 亚洲国产精品欧美一二99| 日本伊人色综合网| 成人ar影院免费观看视频| a亚洲天堂av| 日韩欧美一级精品久久| 国产精品久久久久久亚洲毛片 | 一区二区成人在线视频| 性做久久久久久久免费看| 国产一区二区三区精品视频 | 在线观看91av| 亚洲欧美日韩综合aⅴ视频| 极品少妇xxxx精品少妇偷拍 | 7777精品伊人久久久大香线蕉经典版下载 | 久久在线观看免费| 亚洲自拍另类综合| 在线免费一区三区| 国产色综合一区| 免费一级欧美片在线观看| 91麻豆福利精品推荐| 国产喂奶挤奶一区二区三区| 裸体歌舞表演一区二区| 欧美日韩国产首页在线观看| 一区二区三区日本| 在线看日韩精品电影| 亚洲欧美日韩在线| 一本久久a久久免费精品不卡| 中文字幕乱码日本亚洲一区二区| 国产一本一道久久香蕉| 欧美三级三级三级爽爽爽| 最新国产成人在线观看| 色综合天天综合| 亚洲精品一二三四区| av电影在线观看完整版一区二区 | 亚洲国产成人在线| 国产精品白丝av| 国产精品国产三级国产普通话99| 香蕉影视欧美成人| 国产高清久久久| 久久久久9999亚洲精品| 成人黄色片在线观看| 亚洲一卡二卡三卡四卡五卡| 欧美精品成人一区二区三区四区| 久久精品国产秦先生| 国产精品另类一区| 欧美日韩国产精品成人| 国内精品免费**视频| 自拍视频在线观看一区二区| 欧美日韩黄色影视| 国产精品综合二区| 亚洲影视在线播放| 国产情人综合久久777777| 8x8x8国产精品| 91国内精品野花午夜精品| 国产乱国产乱300精品| 亚洲韩国精品一区| 亚洲理论在线观看| 国产精品久线观看视频| 久久亚洲影视婷婷| 3751色影院一区二区三区| 97精品国产露脸对白| 国产在线精品一区二区| 日韩av网站在线观看| 亚洲一区二区三区四区的| 亚洲天堂精品视频| 国产精品久线在线观看| 国产欧美一区二区精品忘忧草| 日韩欧美亚洲一区二区| 欧美一区二区三区四区在线观看| 色婷婷综合久久久中文一区二区 | 亚洲成av人片在www色猫咪| 国产精品色噜噜| 国产精品视频第一区| 国产精品美女视频| 1024亚洲合集| 亚洲欧美国产高清| 亚洲嫩草精品久久| 亚洲午夜久久久久久久久久久| 亚洲精品第1页| 亚洲永久精品大片| 麻豆视频观看网址久久| 久久不见久久见免费视频7| 精品一区二区三区免费毛片爱| 麻豆91免费观看| 丁香激情综合国产| 色欧美片视频在线观看在线视频| 欧美视频在线不卡| 欧美成人激情免费网|