文件名称:c#聊天室 C/S架构网络聊天室
文件大小:80KB
文件格式:RAR
更新时间:2013-12-10 14:57:35
聊天室
private int listenport = 5555; //监听端口 private TcpListener listener; //监听对象 private ArrayList clients; //用来保存在线的客户端 private Thread processor; //开启对客户端的监听事件的线程 private Socket clientsocket; //与服务端连接的客户端 private Thread clientservice; //为每一个连接的客户端开一个线程 public Form1() { …… clients = new ArrayList(); processor = new Thread(new ThreadStart(StartListening)); processor.Start(); //开启线程 } //线程处理函数----开启监听 private void StartListening() { listener = new TcpListener(listenport); listener.Start(); while (true) { try { Socket s = listener.AcceptSocket(); clientsocket = s; clientservice = new Thread(new ThreadStart(ServiceClient)); clientservice.Start(); } catch(Exception e) { Console.WriteLine(e.ToString()); } } }
【文件预览】:
Chat
----Client()
--------Form1.cs(11KB)
--------bin()
--------obj()
--------Properties()
--------Program.cs(465B)
--------Form1.Designer.cs(7KB)
--------Form1.resx(6KB)
--------Client.csproj(3KB)
----Server()
--------Server.csproj(3KB)
--------Form1.cs(5KB)
--------bin()
--------obj()
--------Properties()
--------Program.cs(465B)
--------Form1.Designer.cs(2KB)
--------Client.cs(1KB)
--------Form1.resx(6KB)
----Chat.suo(24KB)
----Chat.sln(1KB)