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

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