Example #1
0
        private (IChatClient, IChatTransport) CreateClient(CancellationToken token = default)
        {
            var clientToken = CancellationTokenSource.CreateLinkedTokenSource(testsLifetime.Token, token).Token;

            var(connectedClient, clientTransport) = TestingTransport.CreatePair();
            var chatClient = clientFactory.CreateClient(clientTransport);

            pendingTasks.Add(chatClient.RunAsync(clientToken));
            return(chatClient, connectedClient);
        }
Example #2
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);
        }