当前位置: 首页>>代码示例>>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;未经允许,请勿转载。