Esempio n. 1
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Welcome to chat room client! Follow the white rabbit...");

            int serverPort = 8888;

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

            _clientControl = new ClientControl();
            try
            {
                await _clientControl.Connect(serverPort);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Can't connect to chat server|Error={0}", ex.Message);
                Exit();
            }

            Console.WriteLine("Welcome to our chat server. Please provide a nickname");
            var nickname = Console.ReadLine();

            try
            {
                _clientControl.SendMessage(nickname);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Can't define your nickname|Error={0}", ex.Message);
                Exit();
            }

            var msg = string.Empty;

            do
            {
                msg = Console.ReadLine();

                if (msg == "/exit")
                {
                    break;
                }

                try
                {
                    _clientControl.SendMessage(msg);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Can't send your message|Error={0}", ex.Message);
                }
            } while (msg != "/exit");

            Console.WriteLine("See you later. Bye!");
            Thread.Sleep(3000);
            Exit();
        }
Esempio n. 2
0
 private void btn_Connect_Click(object sender, EventArgs e)
 {
     if (this.btn_Connect.Text == "连接")
     {
         client.Connect(this.txt_ServerIP.Text.Trim(), int.Parse(this.txt_port.Text.Trim()));
         MessageBox.Show("服务器连接成功");
     }
 }
Esempio n. 3
0
        static void Main(string[] args)
        {
            ClientControl client = new ClientControl();

            client.Connect("127.0.0.1", 12345);
            string msg = Console.ReadLine();

            while (msg != "quit")
            {
                client.Send(msg);
                msg = Console.ReadLine();
            }
            Console.ReadKey();
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            ClientControl clientControl = new ClientControl();

            clientControl.Connect("127.0.0.1", 12345);

            Console.WriteLine("请输入要发送的信息");
            string msg = null;

            while (msg != "quit")
            {
                clientControl.Send(msg);
                msg = Console.ReadLine();
            }
            Console.ReadKey();
        }