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


C# ZSocket.SendMore方法代码示例

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


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

示例1: RTReq

		public static void RTReq(string[] args)
		{
			//
			// ROUTER-to-REQ example
			//
			// While this example runs in a single process, that is only to make
			// it easier to start and stop the example. Each thread has its own
			// context and conceptually acts as a separate process.
			//
			// Author: metadings
			//

			using (var context = new ZContext())
			using (var broker = new ZSocket(context, ZSocketType.ROUTER))
			{
				broker.Bind("tcp://*:5671");

				for (int i = 0; i < RTReq_Workers; ++i)
				{
					int j = i; new Thread(() => RTReq_Worker(j)).Start();
				}

				var stopwatch = new Stopwatch();
				stopwatch.Start();

				// Run for five seconds and then tell workers to end
				int workers_fired = 0;
				while (true)
				{
					// Next message gives us least recently used worker
					using (ZMessage identity = broker.ReceiveMessage())
					{
						broker.SendMore(identity[0]);
						broker.SendMore(new ZFrame());

						// Encourage workers until it's time to fire them
						if (stopwatch.Elapsed < TimeSpan.FromSeconds(5))
						{
							broker.Send(new ZFrame("Work harder!"));
						}
						else
						{
							broker.Send(new ZFrame("Fired!"));

							if (++workers_fired == RTReq_Workers)
							{
								break;
							}
						}
					}
				}
			}
		}
开发者ID:ChenXuJasper,项目名称:zguide,代码行数:53,代码来源:rtreq.cs

示例2: PathoPub

		public static void PathoPub(string[] args)
		{
			//
			// Pathological publisher
			// Sends out 1,000 topics and then one random update per second
			//
			// Author: metadings
			//

			if (args == null || args.Length < 1)
			{
				Console.WriteLine();
				Console.WriteLine("Usage: ./{0} PathoPub [Endpoint]", AppDomain.CurrentDomain.FriendlyName);
				Console.WriteLine();
				Console.WriteLine("    Endpoint  Where PathoPub should connect to.");
				Console.WriteLine("              Default is null, Binding on tcp://*:5556");
				Console.WriteLine();
				args = new string[] { null };
			}

			using (var context = new ZContext())
			using (var publisher = new ZSocket(context, ZSocketType.PUB))
			{
				if (args[0] != null)
				{
					publisher.Connect(args[0]);
				}
				else
				{
					publisher.Bind("tcp://*:5556");
				}

				// Ensure subscriber connection has time to complete
				Thread.Sleep(100);

				// Send out all 1,000 topic messages
				for (int topic = 0; topic < 1000; ++topic)
				{
					publisher.SendMore(new ZFrame(string.Format("{0:D3}", topic)));
					publisher.Send(new ZFrame("Save Roger"));
				}

				// Send one random update per second
				var rnd = new Random();
				while (true)
				{
					Thread.Sleep(10);
					publisher.SendMore(new ZFrame(string.Format("{0:D3}", rnd.Next(1000))));
					publisher.Send(new ZFrame("Off with his head!"));
				}
			}
		}
开发者ID:ChenXuJasper,项目名称:zguide,代码行数:52,代码来源:pathopub.cs

示例3: RTDealer_Worker

		static void RTDealer_Worker(int i) 
		{
			using (var context = new ZContext())
			using (var worker = new ZSocket(context, ZSocketType.DEALER))
			{
				worker.IdentityString = "PEER" + i;	// Set a printable identity
				worker.Connect("tcp://127.0.0.1:5671");

				int total = 0;
				while (true)
				{
					// Tell the broker we're ready for work
					worker.SendMore(new ZFrame(worker.Identity));	
					worker.SendMore(new ZFrame());
					worker.Send(new ZFrame("Hi Boss"));	

					// Get workload from broker, until finished
					using (ZMessage msg = worker.ReceiveMessage())
					{
						bool finished = (msg[1].ReadString() == "Fired!");

						if (finished)
						{
							break;
						}
					}

					total++;

					// Do some random work
					Thread.Sleep(1);
				}

				Console.WriteLine("Completed: PEER{0}, {1} tasks", i, total);
			}
		}
开发者ID:ChenXuJasper,项目名称:zguide,代码行数:36,代码来源:rtdealer.cs

示例4: LVCache

		public static void LVCache(string[] args)
		{
			//
			// Last value cache
			// Uses XPUB subscription messages to re-send data
			//
			// Author: metadings
			//

			using (var context = new ZContext())
			using (var frontend = new ZSocket(context, ZSocketType.SUB))
			using (var backend = new ZSocket(context, ZSocketType.XPUB))
			{
				// Subscribe to every single topic from publisher
				frontend.Bind("tcp://*:5557");
				frontend.SubscribeAll();

				backend.Bind("tcp://*:5558");

				// Store last instance of each topic in a cache
				var cache = new HashSet<LVCacheItem>();

				// We route topic updates from frontend to backend, and
				// we handle subscriptions by sending whatever we cached,
				// if anything:
				var p = ZPollItem.CreateReceiver();
				ZMessage msg;
				ZError error;
				while (true)
				{
					// Any new topic data we cache and then forward
					if (frontend.PollIn(p, out msg, out error, TimeSpan.FromMilliseconds(1)))
					{
						using (msg)
						{
							string topic = msg[0].ReadString();
							string current = msg[1].ReadString();

							LVCacheItem previous = cache.FirstOrDefault(item => topic == item.Topic);
							if (previous != null)
							{
								cache.Remove(previous);
							}
							cache.Add(new LVCacheItem { Topic = topic, Current = current });

							backend.Send(msg);
						}
					}
					else
					{
						if (error == ZError.ETERM)
							break;	// Interrupted
						if (error != ZError.EAGAIN)
							throw new ZException(error);
					}

					// When we get a new subscription, we pull data from the cache:
					if (backend.PollIn(p, out msg, out error, TimeSpan.FromMilliseconds(1)))
					{
						using (msg)
						{
							// Event is one byte 0=unsub or 1=sub, followed by topic
							byte subscribe = msg[0].ReadAsByte();
							if (subscribe == 0x01)
							{
								string topic = msg[0].ReadString();
								LVCacheItem previous = cache.FirstOrDefault(item => topic == item.Topic);
								if (previous != null)
								{
									Console.WriteLine("Sending cached topic {0}", topic);
									backend.SendMore(new ZFrame(previous.Topic));
									backend.Send(new ZFrame(previous.Current));
								}
								else
								{
									Console.WriteLine("Failed to send cached topic {0}!", topic);
								}
							}
						}
					}
					else
					{
						if (error == ZError.ETERM)
							break;	// Interrupted
						if (error != ZError.EAGAIN)
							throw new ZException(error);
					}
				}
			}
		}
开发者ID:ChenXuJasper,项目名称:zguide,代码行数:90,代码来源:lvcache.cs


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