public static void SerializeCommand(PokeCommand command, Stream stream)
        {
            var type = (byte)command.Type;

            stream.WriteByte(type);
            command.Serialize(stream);
        }
示例#2
0
        /// <summary>
        /// Sends a command to all connected clients.
        /// </summary>
        /// <param name="command">The command to send.</param>
        public void SendCommandToAll(PokeCommand command)
        {
            IList <Socket> failedClients = new List <Socket>();

            lock (_clients)
            {
                foreach (var socket in _clients)
                {
                    try
                    {
                        using (var netStream = new NetworkStream(socket, false))
                        {
                            using (var bufStream = new BufferedStream(netStream))
                            {
                                CommandSerialization.SerializeCommand(command, bufStream);
                            }
                        }
                    }
                    catch (IOException)
                    {
                        failedClients.Add(socket);
                    }
                }
                foreach (var socket in failedClients)
                {
                    _clients.Remove(socket);
                    socket.Close();
                }
            }
        }
示例#3
0
 public void SendCommand(PokeCommand command)
 {
     using (var netStream = new NetworkStream(_socket, false))
     {
         using (var bufStream = new BufferedStream(netStream))
         {
             CommandSerialization.SerializeCommand(command, bufStream);
         }
     }
 }