示例#1
0
        private void ProcessServerResponse()
        {
            int byteNum;

            try
            {
                while (connected)
                {
                    if ((byteNum = reader.ReadInt32()) != 0)
                    {
                        byte[]       buffer    = reader.ReadBytes(byteNum);
                        MemoryStream memstream = new MemoryStream(buffer);

                        Packet packet = formatter.Deserialize(memstream) as Packet;

                        switch (packet.packetType)
                        {
                        case PacketType.ChatMessage:
                            ChatMessagePacket chatPacket = (ChatMessagePacket)packet;
                            clientForm.UpdateChatWindow(chatPacket.message);
                            break;

                        case PacketType.UserListPacket:
                            UserListPacket listPacket = (UserListPacket)packet;
                            clientForm.UserListBox_Edit(listPacket.userList);
                            break;

                        case PacketType.PrivateMessage:
                            PrivateMessagePacket msgPacket = (PrivateMessagePacket)packet;
                            clientForm.OpenPrivateMessage(msgPacket.sender, msgPacket.message);
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }