public byte[] GetData() { ChatSerializer serializer = new ChatSerializer(); serializer.Serialize(m_packet); return(serializer.GetSerializedData()); }
private void sendMessage() { var buffer = new ByteBuffer(); buffer.WriteByte((byte)Protocol.GlobalMessage) .WriteByteArray(serializer.Serialize(new GlobalMessage() { Message = GlobalMessageBox.Text })); socket.Send(buffer.ToArray()); }
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()); } } }
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(); } }