Beispiel #1
0
        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++;
                }
            });
        }