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

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

?? form1.cs

?? 聊天室程序的代碼下載(客戶端與服務器器端)
?? CS
字號:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Threading;


namespace test_socket_client
{
	/// <summary>
	/// Form1 的摘要說明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button3;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.CheckBox checkBox1;
		private System.Windows.Forms.StatusBar statusBar1;
		private TcpClient clientsocket;
		private string serveraddress="127.0.0.1";
		private int serverport = 5555;
		private NetworkStream ns;
		private StreamReader sr;
		private bool connected = false;
		private bool keepalive = true;
		private string clientname = "lixj";
		private Thread th;
		private System.Windows.Forms.ListBox lbChatters;
		private System.Windows.Forms.RichTextBox rtbChatIn;
		private System.Windows.Forms.Button btnSend;
		private System.Windows.Forms.Button btnDisconnect;
		private System.Windows.Forms.TextBox textBox2;
		private System.Windows.Forms.Label label1;
		/// <summary>
		/// 必需的設計器變量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// Windows 窗體設計器支持所必需的
			//
			InitializeComponent();
			//
			// TODO: 在 InitializeComponent 調用后添加任何構造函數代碼
			//
		}

		/// <summary>
		/// 清理所有正在使用的資源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows 窗體設計器生成的代碼
		/// <summary>
		/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
		/// 此方法的內容。
		/// </summary>
		private void InitializeComponent()
		{
			this.lbChatters = new System.Windows.Forms.ListBox();
			this.rtbChatIn = new System.Windows.Forms.RichTextBox();
			this.button1 = new System.Windows.Forms.Button();
			this.button3 = new System.Windows.Forms.Button();
			this.btnSend = new System.Windows.Forms.Button();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.checkBox1 = new System.Windows.Forms.CheckBox();
			this.statusBar1 = new System.Windows.Forms.StatusBar();
			this.btnDisconnect = new System.Windows.Forms.Button();
			this.textBox2 = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// lbChatters
			// 
			this.lbChatters.ItemHeight = 12;
			this.lbChatters.Location = new System.Drawing.Point(8, 24);
			this.lbChatters.Name = "lbChatters";
			this.lbChatters.Size = new System.Drawing.Size(160, 196);
			this.lbChatters.TabIndex = 0;
			// 
			// rtbChatIn
			// 
			this.rtbChatIn.Location = new System.Drawing.Point(176, 24);
			this.rtbChatIn.Name = "rtbChatIn";
			this.rtbChatIn.Size = new System.Drawing.Size(368, 312);
			this.rtbChatIn.TabIndex = 2;
			this.rtbChatIn.Text = "";
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(40, 256);
			this.button1.Name = "button1";
			this.button1.TabIndex = 3;
			this.button1.Text = "連 接";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// button3
			// 
			this.button3.Enabled = false;
			this.button3.Location = new System.Drawing.Point(40, 320);
			this.button3.Name = "button3";
			this.button3.TabIndex = 5;
			this.button3.Text = "開始記錄";
			// 
			// btnSend
			// 
			this.btnSend.Location = new System.Drawing.Point(472, 344);
			this.btnSend.Name = "btnSend";
			this.btnSend.TabIndex = 6;
			this.btnSend.Text = "發 送";
			this.btnSend.Click += new System.EventHandler(this.btnSend_Click);
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(176, 344);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(280, 21);
			this.textBox1.TabIndex = 7;
			this.textBox1.Text = "";
			// 
			// checkBox1
			// 
			this.checkBox1.Location = new System.Drawing.Point(40, 344);
			this.checkBox1.Name = "checkBox1";
			this.checkBox1.TabIndex = 8;
			this.checkBox1.Text = "悄悄話";
			// 
			// statusBar1
			// 
			this.statusBar1.Location = new System.Drawing.Point(0, 375);
			this.statusBar1.Name = "statusBar1";
			this.statusBar1.Size = new System.Drawing.Size(552, 22);
			this.statusBar1.TabIndex = 9;
			// 
			// btnDisconnect
			// 
			this.btnDisconnect.Enabled = false;
			this.btnDisconnect.Location = new System.Drawing.Point(40, 288);
			this.btnDisconnect.Name = "btnDisconnect";
			this.btnDisconnect.TabIndex = 4;
			this.btnDisconnect.Text = "斷開連接";
			this.btnDisconnect.Click += new System.EventHandler(this.btnDisconnect_Click);
			// 
			// textBox2
			// 
			this.textBox2.Location = new System.Drawing.Point(8, 232);
			this.textBox2.Name = "textBox2";
			this.textBox2.Size = new System.Drawing.Size(160, 21);
			this.textBox2.TabIndex = 10;
			this.textBox2.Text = "";
			// 
			// label1
			// 
			this.label1.ForeColor = System.Drawing.SystemColors.Desktop;
			this.label1.Location = new System.Drawing.Point(192, 8);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(100, 16);
			this.label1.TabIndex = 11;
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(552, 397);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.textBox2);
			this.Controls.Add(this.statusBar1);
			this.Controls.Add(this.checkBox1);
			this.Controls.Add(this.textBox1);
			this.Controls.Add(this.btnSend);
			this.Controls.Add(this.button3);
			this.Controls.Add(this.btnDisconnect);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.rtbChatIn);
			this.Controls.Add(this.lbChatters);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
			this.MaximizeBox = false;
			this.Name = "Form1";
			this.Text = "Form1";
			this.Closed += new System.EventHandler(this.Form1_Closed);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 應用程序的主入口點。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}
		private void EstablishConnection() 
		{ 
			statusBar1.Text = "正在連接到服務器"; 
			try 
			{ 
				clientsocket = new TcpClient(serveraddress,serverport); 
				ns = clientsocket.GetStream(); 
				sr = new StreamReader(ns); 
				connected = true; 
				RegisterWithServer();
			} 
			catch (Exception ex) 
			{ 
				MessageBox.Show(ex.Message,"錯誤", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); 
				statusBar1.Text = "已斷開連接"; 
				this.keepalive = false;
			} 

		}  
		private void RegisterWithServer() 
		{ 
			try 
			{ 
				string command = "CONN|" + this.textBox2.Text.ToString(); 
				Byte[] outbytes = System.Text.Encoding.Default.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 = "已連接"; 
					btnDisconnect.Enabled = true; 
				} 
				for(int n=1; n<tokens.Length;n++)
					lbChatters.Items.Add(tokens[n].Trim(new char[]{'\r','\n'})); 
				this.Text = this.textBox2.Text.ToString() + ":已連接到服務器"; 
				this.button1.Enabled = false;


			} 
			catch (Exception) 
			{ 
				MessageBox.Show("注冊時發生錯誤!","錯誤", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); 
			} 
		}  
		private void ReceiveChat() 
		{  
			while (keepalive) 
			{ 
				try 
				{ 
					Byte[] buffer = new Byte[2048]; 
					ns.Read(buffer,0,buffer.Length); 
					string chatter = System.Text.Encoding.Default.GetString(buffer); 
					string[] tokens = chatter.Split(new Char[]{'|'}); 

					if (tokens[0] == "CHAT") 
					{ 
						rtbChatIn.AppendText(tokens[1]); 
					} 
					if (tokens[0] == "PRIV") 
					{ 
						rtbChatIn.AppendText("Private from "); 
						rtbChatIn.AppendText(tokens[1].Trim() ); 
						rtbChatIn.AppendText(tokens[2] + "\r\n"); 
					} 
					if (tokens[0] == "JOIN") 
					{ 
						rtbChatIn.AppendText(tokens[1].Trim() ); 
						rtbChatIn.AppendText(" has joined the Chat\r\n"); 
						string newguy = tokens[1].Trim(new char[]{'\r','\n'}); 
						lbChatters.Items.Add(newguy); 
						this.label1.Text = newguy;
					} 
					if (tokens[0] == "GONE") 
					{ 
						rtbChatIn.AppendText(tokens[1].Trim() ); 
						rtbChatIn.AppendText(" has left the Chat\r\n"); 
						lbChatters.Items.Remove(tokens[1].Trim(new char[]{'\r','\n'})); 
					} 
					if (tokens[0] == "QUIT") 
					{ 
						ns.Close(); 
						clientsocket.Close(); 
						keepalive = false; 
						statusBar1.Text = "服務器端已停止"; 
						connected= false; 
						btnSend.Enabled = false; 
						btnDisconnect.Enabled = false; 
					} 
				} 
				catch(Exception){} 
			} 
		}  
		private void QuitChat() 
		{ 
			if(connected) 
			{ 
				try 
				{ 
					string command = "GONE|" + this.textBox2.Text.ToString(); 
					Byte[] outbytes = System.Text.Encoding.Default.GetBytes(command.ToCharArray()); 
					ns.Write(outbytes,0,outbytes.Length); 
					clientsocket.Close(); 
					this.th.Abort();
					this.th.Join();
				} 
				catch(Exception) 
				{ 
				} 
			} 
			this.lbChatters.Items.Remove(this.textBox1.Text.ToString());
			this.Text = "客戶端"; 
			statusBar1.Text = "已斷開連接"; 
			this.button1.Enabled = true;
			this.btnDisconnect.Enabled = false;
		}

		private void btnSend_Click(object sender, System.EventArgs e)
		{
			string command = "CHAT|" + clientname + ":" + this.textBox1.Text.ToString().Trim()+ "\n"; 
			Byte[] outbytes = System.Text.Encoding.Default.GetBytes(command.ToCharArray()); 
			ns.Write(outbytes,0,outbytes.Length); 
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			EstablishConnection();
			this.clientname = this.textBox2.Text.ToString();
			th = new Thread(new ThreadStart(ReceiveChat));//新建一個用于監聽的線程
         th.Start();//打開新線程
		}

		private void btnDisconnect_Click(object sender, System.EventArgs e)
		{
			this.QuitChat();
		}

		private void Form1_Closed(object sender, System.EventArgs e)
		{
			this.th.Abort();
			this.th.Join();
		}


	}
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
蜜臂av日日欢夜夜爽一区| 亚洲国产aⅴ天堂久久| 国产成a人无v码亚洲福利| 久久久久久久久久久久久女国产乱 | 天天综合天天做天天综合| 在线看日本不卡| 亚洲成人www| 欧美sm美女调教| 国产成人一级电影| 综合色天天鬼久久鬼色| 欧美主播一区二区三区美女| 青青草原综合久久大伊人精品优势 | 色综合久久久久综合| 亚洲一区日韩精品中文字幕| 欧美一级高清片| 国产**成人网毛片九色| 亚洲影院免费观看| 精品捆绑美女sm三区| 99精品视频在线播放观看| 午夜欧美一区二区三区在线播放| 日韩亚洲电影在线| 成人在线视频首页| 亚洲高清免费一级二级三级| 精品av久久707| 在线免费一区三区| 国产一二三精品| 亚洲自拍都市欧美小说| 久久综合999| 91毛片在线观看| 久久精品国产**网站演员| 日本一区二区三区久久久久久久久不| 91麻豆精品视频| 蜜臀av性久久久久蜜臀av麻豆| 国产精品久久久久三级| 欧美一区二区网站| 97久久精品人人做人人爽50路| 日韩国产欧美在线播放| 国产精品免费免费| 91麻豆精品国产自产在线观看一区| 国产成人免费xxxxxxxx| 婷婷六月综合网| 国产精品久久久久影院老司| 欧美大片在线观看一区| 欧美羞羞免费网站| 粉嫩绯色av一区二区在线观看| 男女视频一区二区| 一区二区欧美在线观看| 国产精品天干天干在观线| 精品奇米国产一区二区三区| 欧美中文字幕一区| 99v久久综合狠狠综合久久| 美女免费视频一区二区| 亚洲国产视频直播| 亚洲另类春色校园小说| 国产精品久久久久影院| 久久久美女艺术照精彩视频福利播放 | 一区二区三区中文字幕电影| 中文字幕精品一区二区三区精品| 日韩视频永久免费| 欧美精选一区二区| 欧美亚洲免费在线一区| 色综合一个色综合亚洲| 99热这里都是精品| 国产xxx精品视频大全| 蜜臀99久久精品久久久久久软件| 亚洲成a人v欧美综合天堂| 亚洲激情成人在线| 亚洲欧美国产77777| 亚洲婷婷综合久久一本伊一区| 国产色产综合产在线视频| 久久婷婷色综合| 欧美xxx久久| 精品国产成人系列| 亚洲精品在线免费观看视频| 欧美电影免费观看完整版| 日韩一区二区三区精品视频| 在线不卡中文字幕播放| 制服丝袜激情欧洲亚洲| 欧美日韩三级在线| 欧美日本韩国一区二区三区视频| 欧美日韩中文另类| 欧美精选在线播放| 日韩午夜激情免费电影| 精品乱人伦一区二区三区| 日韩欧美精品在线| 欧美xxx久久| 中文字幕乱码日本亚洲一区二区| 亚洲国产岛国毛片在线| 亚洲欧美综合另类在线卡通| 亚洲欧美日韩人成在线播放| 亚洲午夜精品久久久久久久久| 亚洲国产精品久久人人爱| 日韩精品电影在线| 九九在线精品视频| 国产a区久久久| 色综合色狠狠综合色| 欧美精品一卡两卡| 欧美精品一区二区三区一线天视频| 久久综合色婷婷| 亚洲免费视频成人| 天天影视色香欲综合网老头| 久久不见久久见免费视频1| 国产999精品久久久久久绿帽| av亚洲精华国产精华| 91久久国产最好的精华液| 欧美一区二区三区思思人| 久久久99久久精品欧美| 国产精品国产三级国产普通话99| 亚洲自拍偷拍综合| 激情av综合网| 色激情天天射综合网| 日韩免费福利电影在线观看| 亚洲欧洲三级电影| 蜜臀av国产精品久久久久| 成人av在线一区二区三区| 91久久精品午夜一区二区| 精品国产免费人成电影在线观看四季 | 欧美乱熟臀69xxxxxx| 久久精品水蜜桃av综合天堂| 亚洲手机成人高清视频| 久久黄色级2电影| 91偷拍与自偷拍精品| 欧美电影免费观看高清完整版| 亚洲欧美色综合| 韩国一区二区三区| 精品视频在线视频| 国产清纯白嫩初高生在线观看91 | 日本不卡一二三区黄网| 成人精品gif动图一区| 91精品国产美女浴室洗澡无遮挡| 欧美激情一区二区在线| 青青草国产精品97视觉盛宴| 91在线小视频| 久久先锋资源网| 性欧美疯狂xxxxbbbb| av不卡免费电影| 欧美精品一区男女天堂| 婷婷久久综合九色综合绿巨人 | 日本中文一区二区三区| 91蜜桃传媒精品久久久一区二区| 精品成a人在线观看| 午夜精品久久久久久| 99久久99精品久久久久久| 国产三级三级三级精品8ⅰ区| 日韩av电影免费观看高清完整版| 91欧美激情一区二区三区成人| 欧美精品一区二区三区很污很色的 | 免费观看日韩电影| 欧美色爱综合网| 一区二区三区日韩欧美精品| aa级大片欧美| 欧美国产欧美亚州国产日韩mv天天看完整| 奇米777欧美一区二区| 在线不卡免费av| 性做久久久久久久久| 欧美性欧美巨大黑白大战| 国产精品久久久久久久久果冻传媒 | 欧美一区二区啪啪| 亚洲国产aⅴ成人精品无吗| 日本久久一区二区| 亚洲日本在线观看| eeuss影院一区二区三区| 国产人成一区二区三区影院| 国产成人精品免费网站| 久久久精品2019中文字幕之3| 国内精品免费**视频| 2022国产精品视频| 国产激情视频一区二区在线观看 | 东方欧美亚洲色图在线| 欧美国产日韩亚洲一区| 成人av在线播放网址| 欧美国产一区二区在线观看| 懂色一区二区三区免费观看| 国产精品二三区| 色综合色综合色综合色综合色综合| 亚洲少妇屁股交4| 欧美视频中文字幕| 三级在线观看一区二区| 91精品国产综合久久国产大片 | 成人国产精品免费观看视频| 中文在线免费一区三区高中清不卡| av一区二区三区四区| 亚洲国产一二三| 日韩一级大片在线观看| 国产成人综合在线| 亚洲精品中文在线影院| 欧美日产国产精品| 国产在线国偷精品产拍免费yy| 国产精品沙发午睡系列990531| 一本到不卡精品视频在线观看| 亚洲妇熟xx妇色黄| 日韩一区二区三区av| 国产精品亚洲第一区在线暖暖韩国| 中文字幕二三区不卡| 欧美性受xxxx黑人xyx性爽| 蜜臀a∨国产成人精品| 亚洲国产精品成人综合色在线婷婷| 色综合天天综合网天天狠天天| 日韩av在线免费观看不卡| 久久综合九色综合欧美98|