Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
 public void Broadcast(ChatPacket sendPacket)
 {
     BeginBroadcast(sendPacket);
 }
Exemplo n.º 3
0
        public static byte[] CreatePacket(ChatPacket cp)
        {
            var json = JsonConvert.SerializeObject(cp);

            return(Encoding.ASCII.GetBytes(json));
        }
Exemplo n.º 4
0
 public ChatEventArgs(PacketHeader header, ChatPacket body)
     : base(header.UserId, header.SequenceNumber)
 {
     DestinationUserId = body.DestinationId;
     ChatContent       = body.ChatContent;
 }
Exemplo n.º 5
0
 public ChatEventArgs(PacketHeader header, ChatPacket body)
     : base(header.UserId, header.SequenceNumber)
 {
     DestinationUserId = body.DestinationId;
     ChatContent = body.ChatContent;
 }