Ejemplo n.º 1
0
        public void Unsubscribe()
        {
            using (var pub = new XPublisherSocket())
                using (var sub = new XSubscriberSocket())
                {
                    var port = pub.BindRandomPort("tcp://127.0.0.1");
                    sub.Connect("tcp://127.0.0.1:" + port);
                    sub.SendFrame(new byte[] { 1, (byte)'A' });

                    // let the subscriber connect to the publisher before sending a message
                    Thread.Sleep(500);

                    pub.SendMoreFrame("A");
                    pub.SendFrame("Hello");

                    bool more;

                    Assert.AreEqual("A", sub.ReceiveFrameString(out more));
                    Assert.IsTrue(more);

                    Assert.AreEqual("Hello", sub.ReceiveFrameString(out more));
                    Assert.False(more);

                    sub.SendFrame(new byte[] { 0, (byte)'A' });

                    Thread.Sleep(500);

                    pub.SendMoreFrame("A");
                    pub.SendFrame("Hello");

                    string str;
                    Assert.IsFalse(sub.TryReceiveFrameString(out str));
                }
        }