Beispiel #1
0
        public async Task <byte[]> Write(byte[] message)
        {
            TcpMessage requestMessage = TcpMessage.CreateMessage(message);

            byte[] requestBuffer = requestMessage.GetBufferedMessage();
            await this._stream.WriteAsync(requestBuffer, 0, requestBuffer.Length);

            TcpMessage responseMessage = await TcpMessage.ReadMessage(this._stream);

            Interlocked.Increment(ref Writes);
            return(responseMessage.Data);
        }
Beispiel #2
0
        public async Task Read()
        {
            if (!ExecutionContext.IsFlowSuppressed())
            {
                ExecutionContext.SuppressFlow();
            }

            while (true)
            {
                TcpMessage requestMessage = await TcpMessage.ReadMessage(this._stream);

                if (requestMessage == null)
                {
                    return;
                }

                await ProcessMessage(requestMessage);
            }
        }