private static async Task SetupClientAsync() { await Console.Out.WriteLineAsync("Starting the client with delay...").ConfigureAwait(false); await Task.Delay(2000).ConfigureAwait(false); await Console.Out.WriteLineAsync("Starting the client connection now...").ConfigureAwait(false); var quickSocket = await QuickSocketFactory .GetTcpSocketAsync("127.0.0.1", 15001, true) .ConfigureAwait(false); var quickListeningSocket = await QuickSocketFactory .GetListeningTcpSocketAsync("127.0.0.1", 15001, true) .ConfigureAwait(false); var framingStrategy = new TerminatedByteFrameStrategy(); //QuickJsonReader = new Utf8JsonReader<MessageReceipt>(quickListeningSocket, framingStrategy); QuickJsonWriter = new Utf8JsonWriter <Message>(quickSocket, framingStrategy); await QuickJsonWriter .StartWritingAsync() .ConfigureAwait(false); // Publish To Server _ = Task.Run(async() => { var counter = 0; while (true) { await QuickJsonWriter .QueueForWritingAsync(new Message { MessageId = counter, Data = RandomPayload }) .ConfigureAwait(false); await Task.Delay(500).ConfigureAwait(false); counter++; } }); }
private static async Task SetupServerAsync() { await Console.Out.WriteLineAsync("Starting the server connection now...").ConfigureAwait(false); var quickSocket = await QuickSocketFactory .GetTcpSocketAsync("127.0.0.1", 15001, true) .ConfigureAwait(false); var quickListeningSocket = await QuickSocketFactory .GetListeningTcpSocketAsync("127.0.0.1", 15001, true) .ConfigureAwait(false); await Console.Out.WriteLineAsync("Socket now listening...").ConfigureAwait(false); var framingStrategy = new TerminatedByteFrameStrategy(); QuickJsonReader = new Utf8JsonReader <Message>(quickListeningSocket, framingStrategy); //QuickJsonWriter = new Utf8JsonWriter<MessageReceipt>(quickSocket, framingStrategy); await QuickJsonReader .StartReceiveAsync() .ConfigureAwait(false); _ = Task.Run(async() => { await Console.Out.WriteLineAsync("PipeReader waiting to receive data...").ConfigureAwait(false); await foreach (var message in QuickJsonReader.MessageChannelReader.ReadAllAsync()) { await Console .Out .WriteLineAsync($"MessageId: {message.MessageId}\r\nData: {message.Data}\r\n") .ConfigureAwait(false); } }); }