Exemple #1
0
        public void Receive()
        {
            async Task ReceiveAsync()
            {
                using (var server = new RouterSocket("inproc://async"))
                    using (var client = new DealerSocket("inproc://async"))
                    {
                        client.SendFrame("Hello");

                        var(routingKey, _) = await server.ReceiveRoutingKeyAsync();

                        var(message, _) = await server.ReceiveFrameStringAsync();

                        Assert.Equal(message, "Hello");

                        server.SendMoreFrame(routingKey);
                        server.SendFrame(new[] { (byte)0 });

                        var(bytes, _) = await client.ReceiveFrameBytesAsync();

                        Assert.Equal(bytes[0], 0);
                    }
            }

            using (var runtime = new NetMQRuntime())
            {
                runtime.Run(ReceiveAsync());
            }
        }
Exemple #2
0
        public void SendReceive()
        {
            async Task SendReceiveAsync()
            {
                using (var server = new RouterSocket("inproc://async"))
                    using (var client = new DealerSocket("inproc://async"))
                    {
                        await client.SendFrameAsync("Hello");

                        var(routingKey, _) = await server.ReceiveRoutingKeyAsync();

                        var(message, _) = await server.ReceiveFrameStringAsync();

                        Assert.Equal("Hello", message);

                        server.SendMoreFrame(routingKey);
                        server.SendFrame(new[] { (byte)0 });

                        var(bytes, _) = await client.ReceiveFrameBytesAsync();

                        Assert.Equal(new[] { (byte)0 }, bytes);
                    }
            }

            using (var runtime = new NetMQRuntime())
            {
                var t = SendReceiveAsync();
                runtime.Run(t);

                if (t.IsFaulted && t.Exception is AggregateException exc)
                {
                    throw exc.GetBaseException();
                }
            }
        }