private void AcceptCallBack(IAsyncResult ar) { if (ar.AsyncWaitHandle.WaitOne(5000)) { if (IsRunning) { Socket server = (Socket)ar.AsyncState; Socket clientSocket = server.EndAccept(ar); if (mClientCount <= mMaxClient) { client = new ClientPeer(clientSocket, this); lock (mClientList) { mClientList.Add(client); mClientCount++; Console.WriteLine("一个客户端连接进来了"); mMsg = new MessageTool(client, this); } client.RecvDataBuffer = new byte[mMsg.DataBytesMaxLength]; //开始接受来自该客户端的数据 clientSocket.BeginReceive(client.RecvDataBuffer, 0, client.RecvDataBuffer.Length, SocketFlags.None, new AsyncCallback(HandleDataReceived), client); mServerSock.BeginAccept(new AsyncCallback(AcceptCallBack), mServerSock); } else { Console.WriteLine("服务器爆满"); } } } else { Console.WriteLine("超时"); } }
/// <summary> /// 加入房间 /// </summary> /// <param name="_player"></param> /// <param name="_room"></param> public void JoinRoom(ClientPeer _player, RoomManager _room) { _room.AddPlay(_player); }
public void SendResponse(ClientPeer client, ActionCode actionCode, byte[] data) { client.SendResponse(actionCode, data); }
public void HandleRequest(RequestCode requestCode, ActionCode actionCode, byte[] data, ClientPeer client) { mControllerManager.HandleRequest(requestCode, actionCode, data, client); }
public void AddPlay(ClientPeer _player) { PlayList.Add(_player); }