当前位置: 首页>>代码示例>>C#>>正文


C# RouterSocket.ReceiveFrameBytes方法代码示例

本文整理汇总了C#中NetMQ.Sockets.RouterSocket.ReceiveFrameBytes方法的典型用法代码示例。如果您正苦于以下问题:C# RouterSocket.ReceiveFrameBytes方法的具体用法?C# RouterSocket.ReceiveFrameBytes怎么用?C# RouterSocket.ReceiveFrameBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NetMQ.Sockets.RouterSocket的用法示例。


在下文中一共展示了RouterSocket.ReceiveFrameBytes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TwoMessagesFromRouterToDealer

        public void TwoMessagesFromRouterToDealer()
        {
            using (var server = new RouterSocket())
            using (var client = new DealerSocket())
            using (var poller = new NetMQPoller { client })
            {
                var port = server.BindRandomPort("tcp://*");
                client.Connect("tcp://127.0.0.1:" + port);
                var cnt = 0;
                client.ReceiveReady += (sender, e) =>
                {
                    var strs = e.Socket.ReceiveMultipartStrings();
                    foreach (var str in strs)
                    {
                        Console.WriteLine(str);
                    }
                    cnt++;
                    if (cnt == 2)
                    {
                        poller.Stop();
                    }
                };
                byte[] clientId = Encoding.Unicode.GetBytes("ClientId");
                client.Options.Identity = clientId;

                const string request = "GET /\r\n";

                const string response = "HTTP/1.0 200 OK\r\n" +
                        "Content-Type: text/plain\r\n" +
                        "\r\n" +
                        "Hello, World!";

                client.SendFrame(request);

                byte[] serverId = server.ReceiveFrameBytes();
                Assert.AreEqual(request, server.ReceiveFrameString());

                // two messages in a row, not frames
                server.SendMoreFrame(serverId).SendFrame(response);
                server.SendMoreFrame(serverId).SendFrame(response);

                poller.Run();
            }
        }
开发者ID:NetMQ,项目名称:NetMQ3-x,代码行数:44,代码来源:RouterTests.cs

示例2: RawSocket

        public void RawSocket()
        {
            using (var router = new RouterSocket())
            using (var clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
            {
                router.Options.RouterRawSocket = true;
                var port = router.BindRandomPort("tcp://127.0.0.1");

                clientSocket.Connect("127.0.0.1", port);
                clientSocket.NoDelay = true;

                byte[] clientMessage = Encoding.ASCII.GetBytes("HelloRaw");

                int bytesSent = clientSocket.Send(clientMessage);
                Assert.Greater(bytesSent, 0);

                byte[] id = router.ReceiveFrameBytes();
                byte[] message = router.ReceiveFrameBytes();

                router.SendMoreFrame(id).SendMoreFrame(message); // SendMore option is ignored

                var buffer = new byte[16];

                int bytesRead = clientSocket.Receive(buffer);
                Assert.Greater(bytesRead, 0);

                Assert.AreEqual(Encoding.ASCII.GetString(buffer, 0, bytesRead), "HelloRaw");
            }
        }
开发者ID:hdxhan,项目名称:netmq,代码行数:29,代码来源:SocketTests.cs

示例3: Messages_From_Router_To_Dealer_With_Subscription

		public void Messages_From_Router_To_Dealer_With_Subscription()
		{
			Console.Write("Test sending message from publisher(router) to subscribers (dealer).\n");

			int maxMessage = 5;
			CountdownEvent cd = new CountdownEvent(maxMessage);

			string endpoint;

			using (var publisher = new RouterSocket())
			using (var subscriber = new DealerSocket())
			using (var poller = new NetMQPoller { subscriber })
			{
				publisher.Bind("tcp://127.0.0.1:0");
				endpoint = publisher.Options.LastEndpoint;

				subscriber.Connect(endpoint);
				subscriber.ReceiveReady += (sender, e) =>
				{
					var strs = e.Socket.ReceiveMultipartStrings();
					foreach (var str in strs)
					{
						Console.WriteLine("Subscribe: " + str);
					}
					cd.Signal();
				};
				byte[] clientId = Encoding.Unicode.GetBytes("ClientIdTheIsLongerThen32BytesForSureAbsolutelySure");
				subscriber.Options.Identity = clientId;

				const string request = "Ping";

				// Work around "feature" of router/dealer: the publisher does not know the subscriber exists, until it
				// sends at least one message which makes it necessary to open the connection. I believe this is a
				// low-level feature of the TCP/IP transport.
				subscriber.SendFrame(request); // Ping.

				byte[] serverId = publisher.ReceiveFrameBytes();
				//Assert.AreEqual(request, publisher.ReceiveFrameString());

				for (int i = 0; i < maxMessage; i++)
				{
					string msg = string.Format("[message: {0}]", i);
					Console.Write("Publish: {0}\n", msg);
					publisher.SendMoreFrame(serverId).SendFrame(msg);
					//publisher.SendMoreFrame("").SendFrame(msg);
				}

				poller.RunAsync();

				if (cd.Wait(TimeSpan.FromSeconds(10)) == false) // Blocks until _countdown.Signal has been called.
				{
					Assert.Fail("Timed out, this test should complete in less than 10 seconds.");
				}
			}
		}
开发者ID:dalebrubaker,项目名称:NetMQ.ReactiveExtensions,代码行数:55,代码来源:RouterDealerTest2.cs

示例4: Messages_From_Dealer_To_Router

		public void Messages_From_Dealer_To_Router()
		{
			int maxMessage = 5;
			CountdownEvent cd = new CountdownEvent(maxMessage);

			Console.Write("Test sending message from subscribers (dealer) to publisher(router).\n");

			using (var publisher = new RouterSocket())
			using (var subscriber = new DealerSocket())
			using (var poller = new NetMQPoller { subscriber })
			{
				var port = publisher.BindRandomPort("tcp://*");
				subscriber.Connect("tcp://127.0.0.1:" + port);
				subscriber.ReceiveReady += (sender, e) =>
				{
					var strs = e.Socket.ReceiveMultipartStrings();
					foreach (var str in strs)
					{
						Console.WriteLine(str);
					}
					cd.Signal();
				};
				byte[] clientId = Encoding.Unicode.GetBytes("ClientId");
				subscriber.Options.Identity = clientId;

				const string request = "GET /\r\n";

				const string response = "HTTP/1.0 200 OK\r\n" +
						"Content-Type: text/plain\r\n" +
						"\r\n" +
						"Hello, World!";

				subscriber.SendFrame(request);

				byte[] serverId = publisher.ReceiveFrameBytes();
				Assert.AreEqual(request, publisher.ReceiveFrameString());

				for (int i = 0; i < maxMessage; i++)
				{
					publisher.SendMoreFrame(serverId).SendFrame(response);
				}

				poller.RunAsync();

				if (cd.Wait(TimeSpan.FromSeconds(10)) == false) // Blocks until _countdown.Signal has been called.
				{
					Assert.Fail("Timed out, this test should complete in less than 10 seconds.");
				}
			}
		}
开发者ID:dalebrubaker,项目名称:NetMQ.ReactiveExtensions,代码行数:50,代码来源:RouterDealerTest2.cs


注:本文中的NetMQ.Sockets.RouterSocket.ReceiveFrameBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。