全文预览

计算机网络编程 猜数游戏

上传者:蓝天 |  格式:doc  |  页数:16 |  大小:55KB

文档介绍
new Thread(ListenClientConnect);Р myThread.Start();Р buttonStart.Enabled = false;Р buttonStop.Enabled = true;Р }Р /// <summary>接收客户端连接</summary>Р private void ListenClientConnect()Р { TcpClient newClient = null;Р while (true)Р { tryР {Р newClient = myListener.AcceptTcpClient();Р }Р catchР {Р break;Р }Р User user = new User(newClient);Р Thread threadReceive = new Thread(ReceiveData);Р threadReceive.Start(user);Р userList.Add(user); //每接受一个客户端连接,就创建一个对应的线程循环接收该客户端发来的信息Р AddItemToListBox(string.Format("[{0}]进入", newClient.Client.RemoteEndPoint));Р AddItemToListBox(string.Format("当前连接用户数:{0}", userList.Count));//用于显示当前连接的用户数量Р }Р }Р/// <summary>Р /// 处理接收的客户端数据Р /// </summary>Р /// <param name="userState">客户端信息</param>Р private void ReceiveData(object userState)Р { User user = (User)userState;

收藏

分享

举报
下载此文档