コード例 #1
0
        private async Task HandleClient(IConnectionClient tcpClient)
        {
            var clientId = tcpClient.GetId();

            _notification.Warning("Server", $"Client{clientId} connected!");

            var responseSender = new ResponseSender(tcpClient);

            await HandelNewMessage(tcpClient, responseSender);

            _notification.Error("Server", $"Client{clientId} dropped out");
        }
コード例 #2
0
        private async Task HandelNewMessage(IConnectionClient tcpClient, ResponseSender responseSender)
        {
            string message = await GetNewMessage(tcpClient);

            if (message == null)
            {
                return;
            }

            var messageData = MessageFactory.Create(message);

            _notification.Info($"Client {tcpClient.GetId()} said", messageData.Text);

            _ = Task.Run(() => ReplyToMessage(responseSender, messageData));

            await HandelNewMessage(tcpClient, responseSender);
        }