示例#1
0
        public void ProxyPoll()
        {
            using (Context contex = Context.Create())
            {
                Poller poller = new Poller(contex);

                RouterSocket router = contex.CreateRouterSocket();
                router.Bind("tcp://127.0.0.1:5001");

                RequestSocket req = contex.CreateRequestSocket();
                req.Connect("tcp://127.0.0.1:5001");

                ResponseSocket rep = contex.CreateResponseSocket();
                rep.Bind("tcp://127.0.0.1:5002");

                DealerSocket dealer = contex.CreateDealerSocket();
                dealer.Connect("tcp://127.0.0.1:5002");

                poller.AddProxy(router, dealer, true);

                Task pollerTask = Task.Factory.StartNew(poller.Start);

                req.Send("a");

                bool more;

                string m = rep.ReceiveString(out more);

                Assert.AreEqual("a", m);
                Assert.IsFalse(more);

                rep.Send("b");

                string m2 = req.ReceiveString(out more);

                Assert.AreEqual("b", m2);
                Assert.IsFalse(more);

                poller.Stop();

                Thread.Sleep(100);

                Assert.IsTrue(pollerTask.IsCompleted);

                router.Dispose();
                dealer.Dispose();
                req.Dispose();
                rep.Dispose();
            }
        }