public static void TcpChatMain(string[] args)
        {
            // TCP server port
            int port = 1111;

            if (args.Length > 0)
            {
                port = int.Parse(args[0]);
            }

            Console.WriteLine($"TCP server port: {port}");

            Console.WriteLine();

            // Create a new TCP chat server
            var server = new ChatServer(IPAddress.Any, port);

            // Start the server
            Console.Write("Server starting...");
            server.Start();
            Console.WriteLine("Done!");

            Console.WriteLine("Press Enter to stop the server or '!' to restart the server...");

            // Perform text input
            for (; ;)
            {
                string line = Console.ReadLine();
                if (string.IsNullOrEmpty(line))
                {
                    break;
                }

                // Restart the server
                if (line == "!")
                {
                    Console.Write("Server restarting...");
                    server.Restart();
                    Console.WriteLine("Done!");
                    continue;
                }

                // Multicast admin message to all sessions
                line = "(admin) " + line;
                server.Multicast(line);
            }

            // Stop the server
            Console.Write("Server stopping...");
            server.Stop();
            Console.WriteLine("Done!");
        }
        public static void Start(string[] args)
        {
            // TCP server port
            int port = 1111;

            if (args.Length > 0)
            {
                port = int.Parse(args[0]);
            }
            Console.WriteLine($"TCP server port: {port}");

            Console.WriteLine();

            // Create a new TCP chat server
            chatServer = new ChatServer(IPAddress.Any, port);

            // Start the server
            Console.Write("Server starting...");
            chatServer.Start();
            Console.WriteLine("Done!");

            /*Console.WriteLine("Press Enter to stop the server or '!' to restart the server...");
             *
             * // Perform text input
             * for (; ; )
             * {
             *  string line = Console.ReadLine();
             *  if (string.IsNullOrEmpty(line))
             *      break;
             *
             *  // Restart the server
             *  if (line == "!")
             *  {
             *      Console.Write("Server restarting...");
             *      chatServer.Restart();
             *      Console.WriteLine("Done!");
             *      continue;
             *  }
             *
             *  // Multicast admin message to all sessions
             *  line = "(admin) " + line;
             *  chatServer.Multicast(line);
             * }*/
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            // TCP server port
            int port = 1111;

            if (args.Length > 0)
            {
                port = int.Parse(args[0]);
            }

            Console.WriteLine($"TCP server port: {port}");

            Console.WriteLine();

            // Create a new service
            var service = new Service();

            // Start the service
            Console.Write("Service starting...");
            service.Start();
            Console.WriteLine("Done!");

            // Create a new TCP chat server
            var server = new ChatServer(service, port, InternetProtocol.IPv4);

            // Start the server
            Console.Write("Server starting...");
            server.Start();
            Console.WriteLine("Done!");

            Console.WriteLine("Press Enter to stop the server or '!' to restart the server...");

            // Perform text input
            for (;;)
            {
                string line = Console.ReadLine();
                if (line == string.Empty)
                {
                    break;
                }

                // Restart the server
                if (line == "!")
                {
                    Console.Write("Server restarting...");
                    server.Restart();
                    Console.WriteLine("Done!");
                    continue;
                }

                // Multicast admin message to all sessions
                line = "(admin) " + line;
                server.Multicast(line);
            }

            // Stop the server
            Console.Write("Server stopping...");
            server.Stop();
            Console.WriteLine("Done!");

            // Stop the service
            Console.Write("Service stopping...");
            service.Stop();
            Console.WriteLine("Done!");
        }