public MessageDelivery(NetworkStream stream, ServerClient client)
 {
     this.client = client;
     this.stream = stream;
 }
 public void RemoveClient(ServerClient client)
 {
     clientes.Remove(client);
 }
        static void Main(string[] args)
        {
            Console.SetWindowSize(120, 35);

            string ip = GetLocalIPAddress();

            int port = 8999;

            CancellationTokenSource cts = new CancellationTokenSource();

            TcpServer     server = new TcpServer(ip, port);
            MessageRouter router = new MessageRouter(cts.Token);

            Thread runningServer = new Thread(() => {
                try
                {
                    server.StartServer();

                    while (true)
                    {
                        TcpClient tcpclient = server.AcceptClient();
                        Console.WriteLine("Cliente nuevo");

                        ServerClient client = new ServerClient(tcpclient, router);

                        router.AddClient(client);
                    }
                }
                catch (Exception e)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("== ERROR == -" + e.Message);
                    Console.ForegroundColor = ConsoleColor.White;
                }
            });

            try
            {
                runningServer.Start();

                Console.WriteLine("Server running on IP: " + ip + ", PORT: " + port + ".");
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("== ERROR == -" + e.Message);
                Console.ForegroundColor = ConsoleColor.White;
            }

            string command;

            while (true)
            {
                command = Console.ReadLine();

                if (command == "shutdown")
                {
                    //Console.Beep();
                    cts.Cancel();
                    router.WaitToFinish();
                    Environment.Exit(0);
                }
            }
        }
 public void AddClient(ServerClient client)
 {
     clientes.Add(client);
 }