Exemple #1
0
        static void Main(string[] args)
        {
            Console.Write(Constant.Messages.EnterYourUsername);
            var username = Console.ReadLine();

            var c = TcpClientFactory.Instance(username);

            c.ConnectToServer();

            Console.WriteLine();
            Console.WriteLine(Constant.Messages.Info);
            Console.WriteLine();

            MessageReceiver.DoWork += MessageReceiver_ReceiveResponses;
            MessageReceiver.RunWorkerAsync(argument: username);
            MessageReceiver.RunWorkerCompleted += MessageReceiver_RunWorkerCompleted;

            string str;

            do
            {
                str = Console.ReadLine();
                c.Send(str);
            } while (str != Constant.Eof);

            c.Exit();
            Console.ReadKey();
        }
Exemple #2
0
        private static void MessageReceiver_ReceiveResponses(object sender, DoWorkEventArgs e)
        {
            var username = (string)e.Argument;

            e.Result = username;
            if (!string.IsNullOrEmpty(username))
            {
                Console.WriteLine(TcpClientFactory.Instance(username).ReceiveResponse().Data);
            }
        }