Beispiel #1
0
        /// <summary>
        /// 接收文字线程
        /// </summary>
        /// <param name="socket"></param>
        public void ReceiveThread(Socket socket, string id)
        {
            if (whatRecv == 0)  //接收文字
            {
                while (ClientList.haveId(id))
                {
                    if (whatRecv == 0)
                    {
                        Tool.Log("接收死循环开始");
                        string recvStr = MyServer.ReceiveText((Socket)socket);

                        if (recvStr != null)
                        {
                            if (!recvStr.Equals("退出"))
                            {
                                Tool.Log("接收到文字:" + recvStr);

                                SendMessage(id, MSG_RECEIVE, recvStr);
                            }
                            else
                            {
                                Tool.Log("ID为" + id + "的客户端退出");
                                ClientList.Remove(id);
                            }
                        }
                    }
                    else if (whatRecv == 1)                             //接收文件
                    {
                        int ret = MyServer.ReceiveFile((Socket)socket); //接收文件
                        MessageBox.Show("接收返回");                        //不能返回
                        if (ret == Return.SUCCEED)
                        {
                            //SendMessage(MSG_RECEIVE_SUCCEED, "接收成功");
                        }
                        else
                        {
                            //SendMessage(MSG_RECEIVE_FAIL, "接收失败");
                        }
                    }
                }

                Tool.Log("ID为" + id + "的接收死循环结束");
                SendMessage(id, MSG_UPADTE_COUNT, null);
            }
        }