欢迎来到天天文库
浏览记录
ID:19771792
大小:94.50 KB
页数:11页
时间:2018-10-06
《简单的多人聊天(c#.socket).》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、简单的多人聊天(C#.Socket).>>教育资源库usingSystem;usingSystem.Dra.Collections;usingSystem.ponentModel;usingSystem.odel.Containerponents=null;staticintlistenport=6666;Socketclientsocket;privateSystem...1(){Initializeponent();}///<summary>///清理所有正在使用的资源。///</su
2、mmary>protectedoverridevoidDispose(booldisposing){if(disposing){if(clientservice!=null){clientservice.Abort();}if(threadListen!=null){try{threadListen.Abort();}catch(Exceptionex){threadListen=null;}}if(ponents!=null){ponents.Dispose();}}base.Dispose(dis
3、posing);}#regionary>///设计器支持所需的方法-不要使用代码编辑器修改///此方法的内容。///</summary>privatevoidInitializeponent(){this.lbClients=ne.Height=12;this.lbClients.Location=12345678910下一页>>>>这篇文章来自..,。ne.Drae="lbClients";this.lbClients.Size=ne.Dra.Drae="button1";this.bu
4、tton1.TabIndex=1;this.button1.Text="button1";this.button1.Click+=ne.EventHandler(this.button1_Click);////label1//this.label1.Location=ne.Drae="label1";this.label1.Size=ne.Dra1//this.AutoScaleBaseSize=ne.Dra.Drae="Form1";this.Text="Form1";this.Load+=ne.Even
5、tHandler(this.Form1_Load);this.ResumeLayout(false);}#endregion///<summary>///应用程序的主入口点。///</summary>[STAThread]staticvoidMain(){Application.Run(ne1());}privatevoidStartListening(){ TcpListenerlistener=neessageBox.Shoessage);}}}privatevoidServic
6、eClient(){Socketclient=clientsocket;boolkeepalive=true;&nb上一页12345678910下一页>>>>这篇文章来自..,。sp;and=System.Text.Encoding.ASCII.GetString(buffer).Substring(0,bufLen);string[]tokens=clientmand.Split(neand);if(tokens[0]=="CONN"){for(intn=0;n<clients.Count;n++)
7、{Clientcl=(Client)clients[n];SendToClient(cl,"JOIN
8、"+tokens[1]);}EndPointep=client.RemoteEndPoint;Clientc=neessage="LIST
9、"+GetChatterList()+"r";SendToClient(c,message);clients.Add(c);lbClients.Items.Add(c);}if(tokens[0]=="CHAT"){for(intn=0;n<clients.
10、Count;n++){Clientcl=(Client)clients[n];SendToClient(cl,clientmand);}}if(tokens[0]=="PRIV"){stringdestclient=tokens[3];for(intn=0;n<clients.Count;n++){Clientcl=(Client)clients[n];if(cl.Name.pareTo(tokens[3]
此文档下载收益归作者所有