Stop() public method

public Stop ( ) : void
return void
Exemplo n.º 1
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("usage: Chat.exe [server | client]");
                return;
            }

            if (args[0] == "server")
            {
                Console.WriteLine("Starting server..");

                ChatServer server = new ChatServer();
                server.Start();

                Console.ReadLine();

                server.Stop();
            }
            else if (args[0] == "client")
            {
                Console.WriteLine("Starting client...");

                Console.Write("Enter name: ");

                ChatClient client = new ChatClient(Console.ReadLine());
                client.Start();

                while (true)
                {
                    string line = Console.ReadLine();

                    if (line.StartsWith("@") && line.Length > 1)
                    {
                        string to = line.Substring(1, line.IndexOf(' ') - 1);
                        if (to.Length > 0)
                        {
                            client.Send(to, line.Substring(to.Length + 2));
                        }
                    }
                    else if (line == "quit")
                    {
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Unrecognized command. Send format:\r\n@To message");
                    }
                }

                client.Stop();
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            if(args.Length == 0)
            {
                Console.WriteLine("usage: Chat.exe [server | client]");
                return;
            }

            if (args[0] == "server")
            {
                Console.WriteLine("Starting server..");

                ChatServer server = new ChatServer();
                server.Start();

                Console.ReadLine();

                server.Stop();
            }
            else if (args[0] == "client")
            {
                Console.WriteLine("Starting client...");

                Console.Write("Enter name: ");

                ChatClient client = new ChatClient(Console.ReadLine());
                client.Start();

                while (true)
                {
                    string line = Console.ReadLine();

                    if (line.StartsWith("@") && line.Length > 1)
                    {
                        string to = line.Substring(1, line.IndexOf(' ')-1);
                        if (to.Length > 0)
                        {
                            client.Send(to, line.Substring(to.Length + 2));
                        }
                    }
                    else if (line == "quit")
                    {
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Unrecognized command. Send format:\r\n@To message");
                    }
                }

                client.Stop();
            }
        }