/// <summary> /// Broadcast the packet to all clients. /// </summary> private void BeginBroadcast(ChatPacket sendPacket) { // Get packet as byte array. var data = sendPacket.Serialize(); foreach (var client in Clients) { var state = new StateObject() { EndPoint = client.EndPoint, Data = data }; _serverSocket.BeginSendTo(state.Data, 0, state.Data.Length, SocketFlags.None, client.EndPoint, EndBroadcast, state); } // Report the status. Logger.WriteLine(sendPacket.ChatMessage); }
public void Broadcast(ChatPacket sendPacket) { BeginBroadcast(sendPacket); }
public static byte[] CreatePacket(ChatPacket cp) { var json = JsonConvert.SerializeObject(cp); return(Encoding.ASCII.GetBytes(json)); }
public ChatEventArgs(PacketHeader header, ChatPacket body) : base(header.UserId, header.SequenceNumber) { DestinationUserId = body.DestinationId; ChatContent = body.ChatContent; }