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


C# ZSocket.ReceiveBytes方法代码示例

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


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

示例1: TaskWorker

        public TaskWorker(string workerid="*",string SenderIP = "127.0.0.1", int SenderPort = 5557, string sinkIP = "127.0.0.1", int sinkPort=5558)
        {
            //
            // Task worker
            // Connects PULL socket to tcp://localhost:5557
            // Collects workloads from ventilator via that socket
            // Connects PUSH socket to tcp://localhost:5558
            // Sends results to sink via that socket
            //
            // Author: metadings
            //

            // Socket to receive messages on and
            // Socket to send messages to
            using (var context = new ZContext())
            using (var receiver = new ZSocket(context, ZSocketType.PULL))
            using (var sink = new ZSocket(context, ZSocketType.PUSH))
            {
                receiver.Connect(String.Format ("tcp://{0}:{1}",SenderIP,SenderPort));
                sink.Connect(string.Format("tcp://{0}:{1}",sinkIP,sinkPort ));
                Console.WriteLine("Worker " + workerid + " ready.");
                // Process tasks forever
                while (true)
                {
                    var replyBytes = new byte[4];
                    receiver.ReceiveBytes(replyBytes, 0, replyBytes.Length);
                    int workload = BitConverter.ToInt32(replyBytes, 0);
                    Console.WriteLine("{0}.", workload);    // Show progress

                    Thread.Sleep(workload);    // Do the work

                    sink.Send(new byte[0], 0, 0);    // Send results to sink
                }
            }
        }
开发者ID:jorik041,项目名称:ZeroMQ-Task-Ventilator,代码行数:35,代码来源:TaskWorker.cs

示例2: TaskWork

        public static void TaskWork(string[] args)
        {
            //
            // Task worker
            // Connects PULL socket to tcp://127.0.0.1:5557
            // Collects workloads from ventilator via that socket
            // Connects PUSH socket to tcp://127.0.0.1:5558
            // Sends results to sink via that socket
            //
            // Author: metadings
            //

            // Socket to receive messages on and
            // Socket to send messages to
            using (var context = new ZContext())
            using (var receiver = new ZSocket(context, ZSocketType.PULL))
            using (var sink = new ZSocket(context, ZSocketType.PUSH))
            {
                receiver.Connect("tcp://127.0.0.1:5557");
                sink.Connect("tcp://127.0.0.1:5558");

                // Process tasks forever
                while (true)
                {
                    var replyBytes = new byte[4];
                    receiver.ReceiveBytes(replyBytes, 0, replyBytes.Length);
                    int workload = BitConverter.ToInt32(replyBytes, 0);
                    Console.WriteLine("{0}.", workload);	// Show progress

                    Thread.Sleep(workload);	// Do the work

                    sink.Send(new byte[0], 0, 0);	// Send results to sink
                }
            }
        }
开发者ID:ChenXuJasper,项目名称:zguide,代码行数:35,代码来源:taskwork.cs

示例3: Espresso_Subscriber

		static void Espresso_Subscriber(ZContext context) 
		{
			// The subscriber thread requests messages starting with
			// A and B, then reads and counts incoming messages.

			using (var subscriber = new ZSocket(context, ZSocketType.SUB))
			{
				subscriber.Connect("tcp://127.0.0.1:6001");
				subscriber.Subscribe("A");
				subscriber.Subscribe("B");

				ZError error;
				int count = 0;
				while (count < 5)
				{
					var bytes = new byte[10];
					int bytesLength;
					if (-1 == (bytesLength = subscriber.ReceiveBytes(bytes, 0, bytes.Length, ZSocketFlags.None, out error)))
					{
						if (error == ZError.ETERM)
							return;	// Interrupted
						throw new ZException(error);
					}

					++count;
				}

				Console.WriteLine("I: subscriber counted {0}", count);
			}
		}
开发者ID:ray-zong,项目名称:zguide,代码行数:30,代码来源:espresso.cs


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