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


C# ZSocket.Send方法代码示例

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


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

示例1: PSEnvPub

        public static void PSEnvPub(string[] args)
        {
            //
            // Pubsub envelope publisher
            //
            // Author: metadings
            //

            // Prepare our context and publisher
            using (var context = new ZContext())
            using (var publisher = new ZSocket(context, ZSocketType.PUB))
            {
                publisher.Linger = TimeSpan.Zero;
                publisher.Bind("tcp://*:5563");

                while (true)
                {
                    // Write two messages, each with an envelope and content
                    using (var message = new ZMessage())
                    {
                        message.Add(new ZFrame("A"));
                        message.Add(new ZFrame("We don't want to see this"));
                        publisher.Send(message);
                    }
                    using (var message = new ZMessage())
                    {
                        message.Add(new ZFrame("B"));
                        message.Add(new ZFrame("We would like to see this"));
                        publisher.Send(message);
                    }
                    Thread.Sleep(1000);
                }
            }
        }
开发者ID:jiania,项目名称:zguide,代码行数:34,代码来源:psenvpub.cs

示例2: 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

示例3: 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

示例4: 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

示例5: RTReq_Worker

		static void RTReq_Worker(int i) 
		{
			using (var context = new ZContext())
			using (var worker = new ZSocket(context, ZSocketType.REQ))
			{
				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.Send(new ZFrame("Hi Boss"));

					// Get workload from broker, until finished
					using (ZFrame frame = worker.ReceiveFrame())
					{
						bool finished = (frame.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,代码行数:33,代码来源:rtreq.cs

示例6: RRClient

		public static void RRClient(string[] args)
		{
			//
			// Hello World client
			// Connects REQ socket to tcp://localhost:5559
			// Sends "Hello" to server, expects "World" back
			//
			// Author: metadings
			//

			// Socket to talk to server
			using (var context = new ZContext())
			using (var requester = new ZSocket(context, ZSocketType.REQ))
			{
				requester.Connect("tcp://127.0.0.1:5559");

				for (int n = 0; n < 10; ++n)
				{
					requester.Send(new ZFrame("Hello"));

					using (ZFrame reply = requester.ReceiveFrame())
					{
						Console.WriteLine("Hello {0}!", reply.ReadString());
					}
				}
			}
		}
开发者ID:ray-zong,项目名称:zguide,代码行数:27,代码来源:rrclient.cs

示例7: Espresso_Publisher

		static void Espresso_Publisher(ZContext context) 
		{
			// The publisher sends random messages starting with A-J:

			using (var publisher = new ZSocket(context, ZSocketType.PUB))
			{
				publisher.Bind("tcp://*:6000");

				ZError error;

				while (true)
				{
					var bytes = new byte[5];
					using (var rng = new System.Security.Cryptography.RNGCryptoServiceProvider())
					{
						rng.GetBytes(bytes);
					}
					var frame = new ZFrame(bytes);
					if (!publisher.Send(frame, out error))
					{
						if (error == ZError.ETERM)
							return;	// Interrupted
						throw new ZException(error);
					}

					Thread.Sleep(1);
				}
			}
		}
开发者ID:09130510,项目名称:zguide,代码行数:29,代码来源:espresso.cs

示例8: 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

示例9: Handle

        private static void Handle(Header header, ZFrame bodyFrame)
        {
            //TODO - really we'd have a message handler factory:
            if (header.BodyType == typeof(SendFulfilmentCommand).Name)
            {
                var command = JsonConvert.DeserializeObject<SendFulfilmentCommand>(bodyFrame.ReadString());
                var client = FulfilmentClientFactory.GetApiClient(command.FulfilmentType);
                try
                {
                    client.Send(command.Address);
                    Console.WriteLine("*** Sent fulfilment, type: {0}, to address: {1}", command.FulfilmentType, command.Address);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("*** Fulfilment failed, resending message");

                    var queueAddress = Config.Get("Queues.Fulfilment.Address");
                    header.HandledCount++;
                    header.LastExceptionMessage = ex.Message;

                    var messageFrames = new List<ZFrame>();
                    messageFrames.Add(new ZFrame(JsonConvert.SerializeObject(header)));
                    messageFrames.Add(bodyFrame);

                    using (var context = new ZContext())
                    using (var sender = new ZSocket(context, ZSocketType.PUSH))
                    {
                        sender.Connect(queueAddress);
                        sender.Send(new ZMessage(messageFrames));
                    }
                }
            }
        }
开发者ID:sixeyed,项目名称:handling-failures,代码行数:33,代码来源:Program.cs

示例10: LBBroker_Client

		// Basic request-reply client using REQ socket
		static void LBBroker_Client(ZContext context, int i)
		{
			// Create a socket
			using (var client = new ZSocket(context, ZSocketType.REQ))
			{
				// Set a printable identity
				client.IdentityString = "CLIENT" + i;

				// Connect
				client.Connect("inproc://frontend");

				using (var request = new ZMessage())
				{
					request.Add(new ZFrame("Hello"));

					// Send request
					client.Send(request);
				}

				// Receive reply
				using (ZMessage reply = client.ReceiveMessage())
				{
					Console.WriteLine("CLIENT{0}: {1}", i, reply[0].ReadString());
				}
			}
		}
开发者ID:ray-zong,项目名称:zguide,代码行数:27,代码来源:lbbroker.cs

示例11: Main

        const int SyncPub_SubscribersExpected = 3; // We wait for 3 subscribers

        #endregion Fields

        #region Methods

        public static void Main(string[] args)
        {
            //
            // Synchronized publisher
            //
            // Author: metadings
            //

            // Socket to talk to clients and
            // Socket to receive signals
            using (var context = new ZContext())
            using (var publisher = new ZSocket(context, ZSocketType.PUB))
            using (var syncservice = new ZSocket(context, ZSocketType.REP))
            {
                publisher.SendHighWatermark = 1100000;
                publisher.Bind("tcp://*:5561");

                syncservice.Bind("tcp://*:5562");

                // Get synchronization from subscribers
                int subscribers = SyncPub_SubscribersExpected;
                do
                {
                    Console.WriteLine("Waiting for {0} subscriber" + (subscribers > 1 ? "s" : string.Empty) + "…", subscribers);

                    // - wait for synchronization request
                    syncservice.ReceiveFrame();

                    // - send synchronization reply
                    syncservice.Send(new ZFrame());
                }
                while (--subscribers > 0);

                // Now broadcast exactly 20 updates followed by END
                Console.WriteLine("Broadcasting messages:");
                for (int i = 0; i < 20; ++i)
                {
                    Console.WriteLine("Sending {0}…", i);
                    publisher.Send(new ZFrame(i));
                }
                publisher.Send(new ZFrame("END"));
            }

            Console.WriteLine("Done.");
            Console.ReadLine();
        }
开发者ID:dshaneg,项目名称:zmqpoc,代码行数:52,代码来源:Program.cs

示例12: PSEnvPub

		public static void PSEnvPub(string[] args)
		{
			//
			// Pubsub envelope publisher
			//
			// Author: metadings
			//

			// Prepare our context and publisher
			using (var context = new ZContext())
			using (var publisher = new ZSocket(context, ZSocketType.PUB))
			{
				publisher.Linger = TimeSpan.Zero;
				publisher.Bind("tcp://*:5563");

				int published = 0;
				while (true)
				{
					// Write two messages, each with an envelope and content

					using (var message = new ZMessage())
					{
						published++;
						message.Add(new ZFrame(string.Format("A {0}", published)));
						message.Add(new ZFrame(string.Format(" We don't like to see this.")));
						Thread.Sleep(1000);

						Console_WriteZMessage("Publishing ", message);
						publisher.Send(message);
					}

					using (var message = new ZMessage())
					{
						published++;
						message.Add(new ZFrame(string.Format("B {0}", published)));
						message.Add(new ZFrame(string.Format(" We do like to see this.")));
						Thread.Sleep(1000);

						Console_WriteZMessage("Publishing ", message);
						publisher.Send(message);
					}
				}
			}
		}
开发者ID:ray-zong,项目名称:zguide,代码行数:44,代码来源:psenvpub.cs

示例13: LBBroker_Worker

		static void LBBroker_Worker(ZContext context, int i)
		{
			// This is the worker task, using a REQ socket to do load-balancing.

			// Create socket
			using (var worker = new ZSocket(context, ZSocketType.REQ))
			{
				// Set a printable identity
				worker.IdentityString = "WORKER" + i;

				// Connect
				worker.Connect("inproc://backend");

				// Tell broker we're ready for work
				using (var ready = new ZFrame("READY"))
				{
					worker.Send(ready);
				}

				ZError error;
				ZMessage request;

				while (true)
				{
					// Get request
					if (null == (request = worker.ReceiveMessage(out error)))
					{
						// We are using "out error",
						// to NOT throw a ZException ETERM
						if (error == ZError.ETERM)
							break;

						throw new ZException(error);
					}

					using (request)
					{
						string worker_id = request[0].ReadString();

						string requestText = request[2].ReadString();
						Console.WriteLine("WORKER{0}: {1}", i, requestText);

						// Send reply
						using (var commit = new ZMessage())
						{
							commit.Add(new ZFrame(worker_id));
							commit.Add(new ZFrame());
							commit.Add(new ZFrame("OK"));

							worker.Send(commit);
						}
					}
				}
			}
		}
开发者ID:ray-zong,项目名称:zguide,代码行数:55,代码来源:lbbroker.cs

示例14: RRBroker

		public static void RRBroker(string[] args)
		{
			//
			// Simple request-reply broker
			//
			// Author: metadings
			//

			// Prepare our context and sockets
			using (var ctx = new ZContext())
			using (var frontend = new ZSocket(ctx, ZSocketType.ROUTER))
			using (var backend = new ZSocket(ctx, ZSocketType.DEALER))
			{
				frontend.Bind("tcp://*:5559");
				backend.Bind("tcp://*:5560");

				// Initialize poll set
				var poll = ZPollItem.CreateReceiver();

				// Switch messages between sockets
				ZError error;
				ZMessage message;
				while (true)
				{
					if (frontend.PollIn(poll, out message, out error, TimeSpan.FromMilliseconds(64)))
					{
						// Process all parts of the message
						Console_WriteZMessage("frontend", 2, message);
						backend.Send(message);
					}
					else
					{
						if (error == ZError.ETERM)
							return;	// Interrupted
						if (error != ZError.EAGAIN)
							throw new ZException(error);
					}

					if (backend.PollIn(poll, out message, out error, TimeSpan.FromMilliseconds(64)))
					{
						// Process all parts of the message
						Console_WriteZMessage(" backend", 2, message);
						frontend.Send(message);
					}
					else
					{
						if (error == ZError.ETERM)
							return;	// Interrupted
						if (error != ZError.EAGAIN)
							throw new ZException(error);
					}
				}
			}
		}
开发者ID:ray-zong,项目名称:zguide,代码行数:54,代码来源:rrbroker.cs

示例15: MTRelay_step1

		static void MTRelay_step1(ZContext ctx) 
		{
			// Connect to step2 and tell it we're ready
			using (var xmitter = new ZSocket(ctx, ZSocketType.PAIR))
			{
				xmitter.Connect("inproc://step2");

				Console.WriteLine("Step 1 ready, signaling step 2");
				xmitter.Send(new ZFrame("READY"));
			}
		}
开发者ID:ChenXuJasper,项目名称:zguide,代码行数:11,代码来源:mtrelay.cs


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