示例#1
0
        private void Listen()
        {
            new Thread(
                async() =>
            {
                while (_listening)
                {
                    while (_tcpClient.Available <= 0)
                    {
                        Thread.Sleep(100);
                    }

                    var messageProtocol = await MessageCommunicator.ReadAsync(_tcpClient);
                    await _protocolProcessor.ProcessAsync(messageProtocol);
                }
            }).Start();
        }
示例#2
0
        private async Task <IClient> GetMeseClientInformation(TcpClient client)
        {
            MeseClient meseClient = null;

            WaitForClient(client);

            var messageProtocol = await MessageCommunicator.ReadAsync(client);

            var name = messageProtocol.GetDataAs <string>();

            if (!string.IsNullOrEmpty(name))
            {
                meseClient = new MeseClient(client, name);
            }

            return(meseClient);
        }
示例#3
0
        public async Task StartListeningAsync()
        {
            while (true)
            {
                try
                {
                    var messageProtocol = await MessageCommunicator.ReadAsync(_meseClient.TcpClient);

                    MessageProtocolReceived?.Invoke(this, new MessageProtocolReceivedEventArgs(messageProtocol));
                }
                catch (IOException exception)
                {
                    ThrowDisconnectException(exception);
                }
                catch (SocketException exception)
                {
                    ThrowDisconnectException(exception);
                }
            }
        }