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

            stream.WriteByte(type);
            command.Serialize(stream);
        }
        /// <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();
                }
            }
        }
 public void SendCommand(PokeCommand command)
 {
     using (var netStream = new NetworkStream(_socket, false))
     {
         using (var bufStream = new BufferedStream(netStream))
         {
             CommandSerialization.SerializeCommand(command, bufStream);
         }
     }
 }