/// <summary> /// 接收消息 /// </summary> /// <param name="clientSocket"></param> private void ReceiveMessage() { while (true) { try { SessionMgr.GetInstance().Foreach((socket) => { if (socket == null) { throw new NullReferenceException("Recv Msg ,Socket is null"); } //通过clientSocket接收数据 byte[] buffer = new byte[bufferSize]; int receiveNumber = socket.Receive(buffer); _dataBuffer.AddData(buffer); }); } catch (Exception ex) { Console.WriteLine(ex.Message); break; } } }
void ListenClientConnect() { while (true) { Socket clientSocket = _listenSocket.Accept(); SessionMgr.GetInstance().AddSession(clientSocket); } }