Example #1
0
        private async Task ClientToHostWorker(Stream stream, IMessagePipeEnd pipe)
        {
            using (stream) {
                while (true)
                {
                    byte[] message;
                    try {
                        message = await pipe.ReadAsync(CommonStartup.CancellationToken);
                    } catch (PipeDisconnectedException) {
                        break;
                    }

                    var sizeBuf = BitConverter.GetBytes(message.Length);
                    try {
                        await stream.WriteAsync(sizeBuf, 0, sizeBuf.Length);

                        await stream.WriteAsync(message, 0, message.Length);

                        await stream.FlushAsync();
                    } catch (IOException) {
                        break;
                    }
                }
            }
        }
Example #2
0
        private static async Task PipeToWebSocketWorker(WebSocket socket, IMessagePipeEnd pipe, CancellationToken cancellationToken)
        {
            while (true)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var message = await pipe.ReadAsync(cancellationToken);

                await socket.SendAsync(new ArraySegment <byte>(message, 0, message.Length), WebSocketMessageType.Binary, true, cancellationToken);
            }
        }
Example #3
0
        private static async Task PipeToWebSocketWorker(WebSocket socket, IMessagePipeEnd pipe, CancellationToken cancellationToken) {
            while (true) {
                cancellationToken.ThrowIfCancellationRequested();

                byte[] message;
                try {
                    message = await pipe.ReadAsync(cancellationToken);
                } catch (PipeDisconnectedException) {
                    break;
                }

                await socket.SendAsync(new ArraySegment<byte>(message, 0, message.Length), WebSocketMessageType.Binary, true, cancellationToken);
            }
        }
        private static async Task PipeToWebSocketWorker(WebSocket socket, IMessagePipeEnd pipe, CancellationToken cancellationToken)
        {
            while (true)
            {
                cancellationToken.ThrowIfCancellationRequested();

                byte[] message;
                try {
                    message = await pipe.ReadAsync(cancellationToken);
                } catch (PipeDisconnectedException) {
                    break;
                }

                await socket.SendAsync(new ArraySegment <byte>(message, 0, message.Length), WebSocketMessageType.Binary, true, cancellationToken);
            }
        }
Example #5
0
        private async Task ClientToHostWorker(Stream stream, IMessagePipeEnd pipe)
        {
            while (true)
            {
                var message = await pipe.ReadAsync(Program.CancellationToken);

                var sizeBuf = BitConverter.GetBytes(message.Length);
                try {
                    await stream.WriteAsync(sizeBuf, 0, sizeBuf.Length);

                    await stream.WriteAsync(message, 0, message.Length);

                    await stream.FlushAsync();
                } catch (IOException) {
                    break;
                }
            }
        }
Example #6
0
        private async Task ClientToHostWorker(Stream stream, IMessagePipeEnd pipe) {
            using (stream) {
                while (true) {
                    byte[] message;
                    try {
                        message = await pipe.ReadAsync(Program.CancellationToken);
                    } catch (PipeDisconnectedException) {
                        break;
                    }

                    var sizeBuf = BitConverter.GetBytes(message.Length);
                    try {
                        await stream.WriteAsync(sizeBuf, 0, sizeBuf.Length);
                        await stream.WriteAsync(message, 0, message.Length);
                        await stream.FlushAsync();
                    } catch (IOException) {
                        break;
                    }
                }
            }
        }