Exemple #1
0
        /// SERVER

        static void Main(string[] args)
        {
            string message;
            bool   status;

            using (var responseSocket = new ResponseSocket("@tcp://*:5252"))
            //using (var requestSocket = new RequestSocket(">tcp://localhost:5252"))
            {
                //Console.WriteLine("requestSocket : Sending 'Hello'");
                //requestSocket.SendFrame("Hello");

                //Start and wait for messages
                //Console.WriteLine("Start and wait for messages");
                //Console.ReadLine();
                while (true)
                {
                    status = responseSocket.TryReceiveFrameString(out message);

                    if (status)
                    {
                        Console.WriteLine("responseSocket : Server Received '{0}'", message);
                        status = responseSocket.TrySendFrame("World");
                        if (status)
                        {
                            continue;
                        }
                        else
                        {
                            //May happen that another frame arrives, before sending, may never happen this scenario.
                            responseSocket.TrySkipFrame();
                        }
                    }
                }

                //Console.WriteLine("responseSocket : Server Received '{0}'", message);
                //Console.WriteLine("responseSocket Sending 'World'");


                //responseSocket.SendFrame("World");
                //Console.WriteLine("Received executed, Sent reponse");
                //Console.ReadLine();
                ////message = requestSocket.ReceiveFrameString();
                //Console.WriteLine("requestSocket : Received '{0}'", message);
                //Console.WriteLine("All Done..");
                //Console.ReadLine();
            }
        }
Exemple #2
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);

                        poller.RunAsync();

                        proxy.Start();

                        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 #3
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)));
                            }
                        }
                }
        }