Example #1
0
        protected async override Task StartAsyncClient()
        {
            Console.Write("Enter your nickname:\n> ");
            string name = Console.ReadLine();

            Dictionary <string, string> credentianls = new Dictionary <string, string>()
            {
                ["name"] = name
            };

            string connectionResult = await client.SendRecieveAsync(JsonConvert.SerializeObject(credentianls));

            if (connectionResult != ChatServer.CONNECTION_ESTABLISHED)
            {
                Console.WriteLine("ERROR: Can't connect to the remote server.\nPress any key to continue...");
                Console.ReadKey();
                return;
            }

            cancellationToken = new CancellationTokenSource();

            AsyncConsole.Init();
            AsyncConsole.WriteLine("========= Welcome to the server =========");
            var OnInputTask = AsyncConsole.ReadLine(OnInput, cancellationToken.Token);
            await client.StartReceiving(OnRecieve, cancellationToken);

            AsyncConsole.WriteLine("ERROR: Server closed the connection.\nPress Enter to continue...");
            await OnInputTask;

            client.Disconnect();
        }
Example #2
0
        protected async virtual Task StartAsyncClient()
        {
            cancellationToken = new CancellationTokenSource();

            AsyncConsole.Init();
            var OnInputTask = AsyncConsole.ReadLine(OnInput, cancellationToken.Token);
            await client.StartReceiving(OnRecieve, cancellationToken);

            AsyncConsole.WriteLine("ERROR: Server closed the connection.\nPress Enter to continue...");
            await OnInputTask;

            client.Disconnect();
        }