示例#1
0
        private void Listen()
        {
            var stream = _tcpClient.GetStream();

            while (_tcpClient.Connected)
            {
                var nextMessage = MessagePackSerializer.Deserialize <MessageHeader>(stream, true);

                IProtocolResponse response = GetNextResponse(stream, nextMessage.NextMessageType);

                if (_responses.ContainsKey(nextMessage.MessageId))
                {
                    _responses[nextMessage.MessageId].Add(response);
                }
                else
                {
                    _logger.Log(LogLevel.Warning, "Message with Invalid Message ID...");
                }
            }
        }
示例#2
0
        protected async Task SendResponse <TResponse>(MessageHeader messageHeader, ConnectionInfo connectionInfo, IProtocolResponse response) where TResponse : class
        {
            await MessagePackSerializer.SerializeAsync(connectionInfo.Stream, new MessageHeader { MessageId = messageHeader.MessageId, NextMessageType = response.MessageType });

            await MessagePackSerializer.SerializeAsync <TResponse>(connectionInfo.Stream, response as TResponse);

            await connectionInfo.Stream.FlushAsync();
        }