示例#1
0
文件: Packet.cs 项目: wyuurla/006772
    public byte[] GetData()
    {
        ChatSerializer serializer = new ChatSerializer();

        serializer.Serialize(m_packet);

        return(serializer.GetSerializedData());
    }
示例#2
0
        private void sendMessage()
        {
            var buffer = new ByteBuffer();

            buffer.WriteByte((byte)Protocol.GlobalMessage)
            .WriteByteArray(serializer.Serialize(new GlobalMessage()
            {
                Message = GlobalMessageBox.Text
            }));
            socket.Send(buffer.ToArray());
        }
示例#3
0
 private void NotifyNewUser()
 {
     using (var response = new ByteBuffer())
     {
         var user = new User {
             Identity = this.Identity, Name = this.Name
         };
         response.WriteByte((byte)Protocol.NewUser)
         .WriteByteArray(serializer.Serialize(user));
         foreach (var client in MainForm.Clients.Where(item => item.Key != this.Identity))
         {
             client.Value.Socket.Send(response.ToArray());
         }
     }
 }
示例#4
0
 private void MessageBox_KeyUp(object sender, KeyEventArgs e)
 {
     if (string.IsNullOrWhiteSpace(MessageBox.Text))
     {
         return;
     }
     if (e.KeyData == Keys.Enter)
     {
         var message = new PrivateMessage()
         {
             To = User, Message = MessageBox.Text
         };
         ByteBuffer buffer = new ByteBuffer();
         buffer.WriteByte((byte)Protocol.PrivateMessage)
         .WriteByteArray(serializer.Serialize(message));
         Socket.Send(buffer.ToArray());
         PrintMessage(MessageBox.Text);
         MessageBox.Clear();
     }
 }