Exemplo n.º 1
0
        public void recv(object sender, SocketAsyncEventArgs e)
        {
            try
            {
                int sum = 0;

                Buffer.BlockCopy(recv_E.Buffer, 0, temp, 0, 4);
                sum = BitConverter.ToInt32(temp, 0);

                switch (sum)
                {
                case (int)PROTOCOL.MESSAGE:
                    //string data = System.Text.Encoding.UTF8.GetString(recv_E.Buffer);
                    message = (CMessage)Packet.Deserialize(recv_E.Buffer, message.GetType());

                    game_main.on_receive_chat_msg(message.GetMessageA());
                    client.Client.ReceiveAsync(recv_E);
                    break;

                case (int)PROTOCOL.GAME_READY:

                    client.Client.ReceiveAsync(recv_E);
                    break;

                case (int)PROTOCOL.GAME_START:
                    GameStart = 1;

                    client.Client.ReceiveAsync(recv_E);
                    break;

                case (int)PROTOCOL.ROOM_IN:

                    client.Client.ReceiveAsync(recv_E);
                    break;

                case (int)PROTOCOL.All_ROOM_IN:
                    room_in = true;

                    client.Client.ReceiveAsync(recv_E);
                    break;

                case (int)PROTOCOL.PLAYER_INFO:

                    playerInfo = (PlayerInfo)Packet.Deserialize(recv_E.Buffer, playerInfo.GetType());

                    client.Client.ReceiveAsync(recv_E);
                    break;
                }
            }
            catch
            {
                Debug.Log("recv Error");
            }
        }