Beispiel #1
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            var wsClient = await Connect(stoppingToken);

            logger.LogInformation("Connected to [remote={Remote}]", remoteUrl);
            var chatClient = clientFactory.CreateClient(new WebSocketChatTransport(wsClient, messageProtocol));

            var clientTask = chatClient.RunAsync(stoppingToken);
            var inputTask  = consoleClient.InteractAsync(chatClient, stoppingToken);

            // In retrospect I could have provided some event or different API to wait for client connection
            await Task.Delay(100, stoppingToken);

            Console.WriteLine($"{chatClient.User.Name} entered the chat");

            await Task.WhenAll(clientTask, inputTask);
        }
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            client.NoDelay = true;
            await client.ConnectAsync(serverAddress, serverPort, stoppingToken);

            logger.LogDebug("Connected to [server={@Server}]", client.Client.RemoteEndPoint);
            var chatClient =
                clientFactory.CreateClient(new TcpChatTransport(client, messageProtocol));

            var connectionTask  = chatClient.RunAsync(stoppingToken);
            var interactionTask = consoleClient.InteractAsync(chatClient, stoppingToken);

            // In retrospect I could have provided some event or different API to wait for client connection
            await Task.Delay(100, stoppingToken);

            Console.WriteLine($"{chatClient.User.Name} entered the chat");

            await Task.WhenAny(connectionTask, interactionTask);
        }