Exemple #1
0
        public void TestProxySendAndReceiveWithExternalPoller()
        {
            using (var front = new RouterSocket())
            using (var back = new DealerSocket())
            using (var poller = new NetMQPoller { front, back })
            {
                front.Bind("inproc://frontend");
                back.Bind("inproc://backend");

                var proxy = new Proxy(front, back, null, poller);
                proxy.Start();

                poller.RunAsync();
                
                using (var client = new RequestSocket())
                using (var server = new ResponseSocket())
                {
                    client.Connect("inproc://frontend");
                    server.Connect("inproc://backend");

                    client.SendFrame("hello");
                    Assert.AreEqual("hello", server.ReceiveFrameString());
                    server.SendFrame("reply");
                    Assert.AreEqual("reply", client.ReceiveFrameString());

                    // Now stop the external poller
                    poller.Stop();

                    client.SendFrame("anyone there?");

                    // Should no longer receive any messages
                    Assert.IsFalse(server.TrySkipFrame(TimeSpan.FromMilliseconds(50)));
                }
            }
        }
Exemple #2
0
        public void StoppingProxyDisengagesFunctionality()
        {
            using (var front = new RouterSocket())
            using (var back = new DealerSocket())
            {
                front.Bind("inproc://frontend");
                back.Bind("inproc://backend");

                var proxy = new Proxy(front, back);
                Task.Factory.StartNew(proxy.Start);

                // Send a message through to ensure the proxy has started
                using (var client = new RequestSocket())
                using (var server = new ResponseSocket())
                {
                    client.Connect("inproc://frontend");
                    server.Connect("inproc://backend");
                    client.SendFrame("hello");
                    Assert.AreEqual("hello", server.ReceiveFrameString());
                    server.SendFrame("reply");
                    Assert.AreEqual("reply", client.ReceiveFrameString());

                    proxy.Stop(); // blocks until stopped

                    using (var poller = new NetMQPoller { front, back })
                    {
                        poller.RunAsync();

                        client.SendFrame("anyone there?");

                        // Should no longer receive any messages
                        Assert.IsFalse(server.TrySkipFrame(TimeSpan.FromMilliseconds(50)));
                    }
                }
            }
        }