當前位置: 首頁>>代碼示例>>C#>>正文


C# DealerSocket.ReceiveFrameString方法代碼示例

本文整理匯總了C#中NetMQ.Sockets.DealerSocket.ReceiveFrameString方法的典型用法代碼示例。如果您正苦於以下問題:C# DealerSocket.ReceiveFrameString方法的具體用法?C# DealerSocket.ReceiveFrameString怎麽用?C# DealerSocket.ReceiveFrameString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在NetMQ.Sockets.DealerSocket的用法示例。


在下文中一共展示了DealerSocket.ReceiveFrameString方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: BindRandom

        public void BindRandom()
        {
            using (var randomDealer = new DealerSocket())
            using (var connectingDealer = new DealerSocket())
            {
                int port = randomDealer.BindRandomPort("tcp://*");
                connectingDealer.Connect("tcp://127.0.0.1:" + port);

                randomDealer.SendFrame("test");

                Assert.AreEqual("test", connectingDealer.ReceiveFrameString());
            }
        }
開發者ID:thomsonreuters,項目名稱:netmq,代碼行數:13,代碼來源:SocketTests.cs

示例2: BindToLocal

        public void BindToLocal()
        {
            var validAliasesForLocalHost = new[] { "127.0.0.1", "localhost", Dns.GetHostName() };

            foreach (var alias in validAliasesForLocalHost)
            {
                using (var localDealer = new DealerSocket())
                using (var connectingDealer = new DealerSocket())
                {
                    var port = localDealer.BindRandomPort("tcp://*");
                    connectingDealer.Connect(string.Format("tcp://{0}:{1}", alias, port));

                    localDealer.SendFrame("test");

                    Assert.AreEqual("test", connectingDealer.ReceiveFrameString());
                    Console.WriteLine(alias + " connected ");
                }
            }
        }
開發者ID:thomsonreuters,項目名稱:netmq,代碼行數:19,代碼來源:SocketTests.cs

示例3: ConnectionStringMultipleAddresses

        public void ConnectionStringMultipleAddresses()
        {
            using (DealerSocket server1 = new DealerSocket("@tcp://127.0.0.1:5555"))
            using (DealerSocket server2 = new DealerSocket("@tcp://127.0.0.1:5556,@tcp://127.0.0.1:5557"))
            using (DealerSocket client = new DealerSocket("tcp://127.0.0.1:5555,tcp://127.0.0.1:5556,tcp://127.0.0.1:5557"))
            {
                // send three helloes
                client.SendFrame("Hello");
                client.SendFrame("Hello");
                client.SendFrame("Hello");

                Assert.AreEqual("Hello", server1.ReceiveFrameString());
                Assert.AreEqual("Hello", server2.ReceiveFrameString());
                Assert.AreEqual("Hello", server2.ReceiveFrameString());
            }
        }
開發者ID:hdxhan,項目名稱:netmq,代碼行數:16,代碼來源:SocketTests.cs

示例4: ReconnectOnRouterBug

        public void ReconnectOnRouterBug()
        {
            {
                using (var dealer = new DealerSocket())
                {
                    dealer.Options.Identity = Encoding.ASCII.GetBytes("dealer");
                    dealer.Bind("tcp://localhost:6667");

                    using (var router = new RouterSocket())
                    {
                        router.Options.RouterMandatory = true;
                        router.Connect("tcp://localhost:6667");
                        Thread.Sleep(100);

                        router.SendMoreFrame("dealer").SendFrame("Hello");
                        var message = dealer.ReceiveFrameString();
                        Assert.That(message == "Hello");

                        router.Disconnect("tcp://localhost:6667");
                        Thread.Sleep(1000);
                        router.Connect("tcp://localhost:6667");
                        Thread.Sleep(100);

                        router.SendMoreFrame("dealer").SendFrame("Hello");
                        message = dealer.ReceiveFrameString();
                        Assert.That(message == "Hello");
                    }
                }
            }
        }
開發者ID:hdxhan,項目名稱:netmq,代碼行數:30,代碼來源:SocketTests.cs

示例5: Ipv6ToIpv6

        public void Ipv6ToIpv6()
        {
            using (var localDealer = new DealerSocket())
            using (var connectingDealer = new DealerSocket())
            {
                localDealer.Options.IPv4Only = false;
                var port = localDealer.BindRandomPort("tcp://*");

                connectingDealer.Options.IPv4Only = false;
                connectingDealer.Connect(string.Format("tcp://{0}:{1}", IPAddress.IPv6Loopback, port));

                connectingDealer.SendFrame("test");

                Assert.AreEqual("test", localDealer.ReceiveFrameString());
            }
        }
開發者ID:hdxhan,項目名稱:netmq,代碼行數:16,代碼來源:SocketTests.cs

示例6: RemoveSocket

        public void RemoveSocket()
        {
            using (var router1 = new RouterSocket())
            using (var router2 = new RouterSocket())
            using (var router3 = new RouterSocket())
            using (var dealer1 = new DealerSocket())
            using (var dealer2 = new DealerSocket())
            using (var dealer3 = new DealerSocket())
            using (var poller = new NetMQPoller { router1, router2, router3 })
            {
                int port1 = router1.BindRandomPort("tcp://127.0.0.1");
                int port2 = router2.BindRandomPort("tcp://127.0.0.1");
                int port3 = router3.BindRandomPort("tcp://127.0.0.1");

                dealer1.Connect("tcp://127.0.0.1:" + port1);
                dealer2.Connect("tcp://127.0.0.1:" + port2);
                dealer3.Connect("tcp://127.0.0.1:" + port3);

                bool first = true;

                router1.ReceiveReady += (s, e) =>
                {
                    if (!first)
                        Assert.Fail("This should not happen because we cancelled the socket");
                    first = false;

                    // identity
                    e.Socket.SkipFrame();

                    bool more;
                    Assert.AreEqual("Hello", e.Socket.ReceiveFrameString(out more));
                    Assert.False(more);

                    // cancelling the socket
                    poller.Remove(e.Socket); // remove self
                };

                router2.ReceiveReady += (s, e) =>
                {
                    // identity
                    byte[] identity = e.Socket.ReceiveFrameBytes();

                    // message
                    e.Socket.SkipFrame();

                    e.Socket.SendMoreFrame(identity);
                    e.Socket.SendFrame("2");
                };

                router3.ReceiveReady += (s, e) =>
                {
                    // identity
                    byte[] identity = e.Socket.ReceiveFrameBytes();

                    // message
                    e.Socket.SkipFrame();

                    e.Socket.SendMoreFrame(identity).SendFrame("3");
                };

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

                // Send three messages. Only the first will be processed, as then handler removes
                // the socket from the poller.
                dealer1.SendFrame("Hello");
                dealer1.SendFrame("Hello2");
                dealer1.SendFrame("Hello3");

                // making sure the socket defined before the one cancelled still works
                dealer2.SendFrame("1");
                Assert.AreEqual("2", dealer2.ReceiveFrameString());

                // making sure the socket defined after the one cancelled still works
                dealer3.SendFrame("1");
                Assert.AreEqual("3", dealer3.ReceiveFrameString());

                poller.Stop();
                Assert.IsTrue(pollerTask.IsCompleted);
            }
        }
開發者ID:cjkao,項目名稱:netmq,代碼行數:80,代碼來源:NetMQPollerTest.cs

示例7: Ipv6ToIpv4

        public void Ipv6ToIpv4()
        {
            using (var localDealer = new DealerSocket())
            using (NetMQSocket connectingDealer = new DealerSocket())
            {
                localDealer.Options.IPv4Only = false;
                var port = localDealer.BindRandomPort("tcp://*");

                connectingDealer.Connect($"tcp://{IPAddress.Loopback}:{port}");

                connectingDealer.SendFrame("test");

                Assert.AreEqual("test", localDealer.ReceiveFrameString());
            }
        }
開發者ID:somdoron,項目名稱:netmq,代碼行數:15,代碼來源:SocketTests.cs

示例8: BindToLocal

        public void BindToLocal()
        {
            var validAliasesForLocalHost = new[] { "127.0.0.1", "localhost", Dns.GetHostName() };

            foreach (var alias in validAliasesForLocalHost)
            {
                using (var localDealer = new DealerSocket())
                using (var connectingDealer = new DealerSocket())
                {
                    var port = localDealer.BindRandomPort("tcp://*");
                    connectingDealer.Connect($"tcp://{alias}:{port}");

                    localDealer.SendFrame("test");

                    Assert.AreEqual("test", connectingDealer.ReceiveFrameString());
                }
            }
        }
開發者ID:somdoron,項目名稱:netmq,代碼行數:18,代碼來源:SocketTests.cs


注:本文中的NetMQ.Sockets.DealerSocket.ReceiveFrameString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。