欢迎来到天天文库
浏览记录
ID:19747448
大小:94.50 KB
页数:11页
时间:2018-10-05
《简单的多人聊天(c#.socket).--》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、简单的多人聊天(C#.Socket).>>usingSystem;usingSystem.Dra.Collections;usingSystem.ponentModel;usingSystem.odel.Containerponents=null;staticintlistenport=6666;Socketclientsocket;privateSystem...1(){Initializeponent();}///<summary>///清理所有正在使用的资源。///</summary>prot
2、ectedoverridevoidDispose(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(disposing);}#regionary&g
3、t;///设计器支持所需的方法-不要使用代码编辑器修改///此方法的内容。///</summary>privatevoidInitializeponent(){this.lbClients=ne.Height=12;this.lbClients.Location=12345678910下一页>>>>这篇文章来自..,。ne.Drae="lbClients";this.lbClients.Size=ne.Dra.Drae="button1";this.button1.TabIndex=1;this.button1
4、.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.EventHandler(this.Form1_Load);this.Resume
5、Layout(false);}#endregion///<summary>///应用程序的主入口点。///</summary>[STAThread]staticvoidMain(){Application.Run(ne1());}privatevoidStartListening(){ TcpListenerlistener=neessageBox.Shoessage);}}}privatevoidServiceClient(){Socketclient=clientsocket;boolkeepa
6、live=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++){Clientcl=(Client)clients[n];SendToClient(cl,"JOIN
7、"+
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.Count;n++){Clientcl=(Client)clients[n];SendToClient(cl,client
10、mand);}}if(tokens[0]=="PRIV"){stringdestclient=tokens[3];for(intn=0;n<clients.Count;n++){Clientcl=(Client)clients[n];if(cl.Name.pareTo(tokens[3])==0)
此文档下载收益归作者所有