/ /
/ / textBox1的,,
/ /
=新System.Drawing.Point this.textBox1.Location(88,16);
this.textBox1.Multiline = TRUE;
this.textBox1.Name =“textBox1的”;
this.textBox1.Size,=新System.Drawing.Size(104,24);
this.textBox1.TabIndex = 1;
this.textBox1.Text =“”;
/ /
/ / textBox2中,,
/ /
this.textBox2.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
this.textBox2.Location =:System.Drawing.Point新(8,64);
this.textBox2.Multiline = TRUE;
this.textBox2.Name =“textBox2中”;
this.textBox2.ReadOnly = TRUE;
this.textBox2.ScrollBars = System.Windows.Forms.ScrollBars.Vertical的;
新System.Drawing.Size this.textBox2.Size =(320,80);
this.textBox2.TabIndex = 2;
this.textBox2.Text =“”;
/ /
/ /按钮
/ /
this.button1.Location =:System.Drawing.Point新(208,16);
this.button1.Name =“Button1”的;
this.button1.Size =新System.Drawing.Size(64,24);
this.button1.TabIndex = 3;
this.button1.Text =“登录”;
this.button1.Click + = System.EventHandler(this.LoginBtn_click)的;
/ /
/ /按钮
/ /
this.button2.Location =新System.Drawing.Point(48,280);
this.button2.Name =“button2的”;
this.button2.Size,=新System.Drawing.Size(72,24);
this.button2.TabIndex = 4;
this.button2.Text =“发送”;
this.button2.Click + = System.EventHandler(this.SendBtn_click)的;
/ /
/ /按钮3
/ /
this.button3.Location =新System.Drawing.Point(200,280);
this.button3.Name =“按钮3”;
this.button3.Size =新System.Drawing.Size(80,24);
this.button3.TabIndex = 5;
this.button3.Text =“断开”;
this.button3.Click + = System.EventHandler(this.DiscBtn_click)的;
/ /
/ / textBox3,
/ /
this.textBox3.Location =:System.Drawing.Point新(8,17??6);
this.textBox3.Multiline = TRUE;
this.textBox3.Name =“textBox3”;
新System.Drawing.Size this.textBox3.Size =(320,88);
this.textBox3.TabIndex = 6;
this.textBox3.Text =“”;
/ /
/ / label1的
/ /
this.label1.Location =:System.Drawing.Point新(48,24);
this.label1.Name =“label1的”;
新System.Drawing.Size this.label1.Size =(40,24);
this.label1.TabIndex = 7;
this.label1.Text =“姓名:”;
/ /
/ / LABEL2
/ /
this.label2.Location =:System.Drawing.Point新(8,48);
this.label2.Name =“label2的”;
this.label2.Size =新System.Drawing.Size(112,16);
this.label2.TabIndex = 8;
this.label2.Text =“收到的消息:”;
/ /
/ / LABEL3,
/ /
this.label3.Location =:System.Drawing.Point新(8,152);
this.label3.Name =“LABEL3”;
this.label3.Size =新System.Drawing.Size(128,16);
this.label3.TabIndex = 9;
this.label3.Text =“要发送的消息:”;
/ /
/ / StatusBar1中,,
/ /
this.statusBar1.Location =新System.Drawing.Point(0,318);
this.statusBar1.Name =“StatusBar1中”;
this.statusBar1.Size =新System.Drawing.Size(336,16);
this.statusBar1.TabIndex = 11;
this.statusBar1.Text =“状态”;
/ /
/ / Form1中
/ /
this.AutoScaleBaseSize =新System.Drawing.Size(6,14);
新System.Drawing.Size this.ClientSize =(336,334);
this.Controls.AddRange(新System.Windows.Forms.Control的[] {
,this.statusBar1,
,this.label3,
this.label2,
,this.label1,
,this.textBox3,
,this.button3,
this.button2,
this.button1,
this.textBox2,
this.textBox1});
this.Name =“Form1的”;
this.Text =“ChatServer”;的
this.ResumeLayout(假);
}
#endregion
/ / /公升; summarygt
/ / /应用程序的主入口点。
/ / / </摘要>
[STAThread]
静态无效的主要()
{
Application.Run(新Form1的());
}
私人的无效LoginBtn_click(对象发件人,发送System.EventArgs)
{
HOSTIP然后我们(“127.0.0.1”);
尝试
{
ChatServer =新的IPEndPoint(HOSTIP,Int32.Parse(“8080”));
=新的Socket ChatSocket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp)的;
ChatSocket.Bind(ChatServer);
ChatSocket.Listen(50);
statusBar1.Text = textBox1.Text +“logoned on.Now开始听......”;
AcceptedSocket = ChatSocket.Accept();
线程线程=新的Thread(新的ThreadStart(ChatProcess)的);
thread.Start();
}
赶上(例外EE)
{statusBar1.Text ee.Message;}
}
私人无效ChatProcess()
{
如果(AcceptedSocket.Connected)
{
statusBar1.Text =“准备在聊天!”;
而(旗)
{
[字节] ReceivedByte =新的字节[64];
AcceptedSocket.Receive(ReceivedByte ReceivedByte.Length,0);
串ReceivedStr = System.Text.Encoding.BigEndianUnicode.GetString(ReceivedByte);
textBox2.AppendText(ReceivedStr +“ R N”);
}
}
}
私人的无效SendBtn_click(对象发件人,发送System.EventArgs)
{
尝试
{
[字节] SentByte =新的字节[64];
串SentStr = textBox1.Text +“............”+ textBox3.Text +“ R N”;
SentByte = System.Text.Encoding.BigEndianUnicode.GetBytes(SentStr.ToCharArray());
AcceptedSocket.Send(SentByte SentByte.Length,0);
textBox3.Clear();
}

{statusBar1.Text =“连接不存在!”;}
}
私人的无效DiscBtn_click(对象发件人,发送System.EventArgs)
{
尝试
{
ChatSocket.Close();
AcceptedSocket.Close();
statusBar1.Text =“断开连接!”
}
{statusBar1.Text =“连接不存在!”;}
}
}
}