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


C# ZSocket.Subscribe方法代码示例

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


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

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

示例2: 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;
				ZFrame frame;
				int count = 0;
				while (count < 5)
				{
					if (null == (frame = subscriber.ReceiveFrame(out error)))
					{
						if (error == ZError.ETERM)
							return;	// Interrupted
						throw new ZException(error);
					}

					++count;
				}

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

示例3: Espresso0_Subscriber

		// The subscriber thread requests messages starting with
		// A and B, then reads and counts incoming messages.
		static void Espresso0_Subscriber(ZContext context) 
		{
			// Subscrie to "A" and "B"
			using (var subscriber = new ZSocket(context, ZSocketType.SUB))
			{
				subscriber.Connect("tcp://127.0.0.1:6001");
				subscriber.Subscribe("A");
				subscriber.Subscribe("B");

				ZError error;
				ZFrame frm;
				int count = 0;
				while (count < 5)
				{
					if (null == (frm = subscriber.ReceiveFrame(out error)))
					{
						if (error == ZError.ETERM)
							return;	// Interrupted
						throw new ZException(error);
					}
					++count;
				}

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

示例4: PSEnvSub

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

			// Prepare our context and subscriber
			using (var context = new ZContext())
			using (var subscriber = new ZSocket(context, ZSocketType.SUB))
			{
				subscriber.Connect("tcp://127.0.0.1:5563");
				subscriber.Subscribe("B");

				int subscribed = 0;
				while (true)
				{
					using (ZMessage message = subscriber.ReceiveMessage())
					{
						subscribed++;

						// Read envelope with address
						string address = message[0].ReadString();

						// Read message contents
						string contents = message[1].ReadString();

						Console.WriteLine("{0}. [{1}] {2}", subscribed, address, contents);
					}
				}
			}
		}
开发者ID:ChenXuJasper,项目名称:zguide,代码行数:33,代码来源:psenvsub.cs

示例5: PathoSub

		public static void PathoSub(string[] args)
		{
			//
			// Pathological subscriber
			// Subscribes to one random topic and prints received messages
			//
			// Author: metadings
			//

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

			using (var context = new ZContext())
			using (var subscriber = new ZSocket(context, ZSocketType.SUB))
			{
				subscriber.Connect(args[0]);

				var rnd = new Random();
				var subscription = string.Format("{0:D3}", rnd.Next(1000));
				subscriber.Subscribe(subscription);

				ZMessage msg;
				ZError error;
				while (true)
				{
					if (null == (msg = subscriber.ReceiveMessage(out error)))
					{
						if (error == ZError.ETERM)
							break;	// Interrupted
						throw new ZException(error);
					}
					using (msg)
					{
						if (msg[0].ReadString() != subscription)
						{
							throw new InvalidOperationException();
						}
						Console.WriteLine(msg[1].ReadString());
					}
				}
			}
		}
开发者ID:ChenXuJasper,项目名称:zguide,代码行数:50,代码来源:pathosub.cs

示例6: Main

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

            string topic;

            if (args == null || !args.Any())
            {
                topic = string.Empty;
                Console.WriteLine("Not filtering messages.");
            }
            else
            {
                topic = args[0];
                Console.WriteLine("Filtering messages by topic '{0}'.", topic);
            }

            // Prepare our context and subscriber
            using (var context = new ZContext())
            using (var subscriber = new ZSocket(context, ZSocketType.SUB))
            {
                subscriber.Connect("tcp://127.0.0.1:5563");
                subscriber.Subscribe(topic);

                while (true)
                {
                    using (ZMessage message = subscriber.ReceiveMessage())
                    {
                        // Read envelope with address
                        string address = message[0].ReadString();

                        // Read message contents
                        string contents = message[1].ReadString();

                        Console.WriteLine("[{0}] {1}", address, contents);
                    }
                }
            }
        }
开发者ID:dshaneg,项目名称:zmqpoc,代码行数:43,代码来源:Program.cs

示例7: BeginListener

        public Task BeginListener(Action<string> callback, CancellationToken cancellationToken = default(CancellationToken))
        {
            return Task.Run(async () =>
            {
                using (var ztx = new ZContext())
                using (var subscriber = new ZSocket(ztx, ZSocketType.SUB))
                {
                    subscriber.Connect("tcp://eddn-relay.elite-markets.net:9500");
                    subscriber.Subscribe("");
                    subscriber.ReceiveTimeout = new TimeSpan(0, 0, 30);

                    while (!cancellationToken.IsCancellationRequested)
                    {
                        var message = await ReceiveMessage(subscriber, cancellationToken);

                        if (message != null)
                            Task.Run(() => callback(message), cancellationToken).Start();
                    }
                }
            }, cancellationToken);
        }
开发者ID:dev-informatics,项目名称:elite.openapi,代码行数:21,代码来源:EddnSubscriberConnection.cs

示例8: WUClient

        public static void WUClient(string[] args)
        {
            //
            // Weather update client
            // Connects SUB socket to tcp://127.0.0.1:5556
            // Collects weather updates and finds avg temp in zipcode
            //
            // Author: metadings
            //

            if (args == null || args.Length < 2)
            {
                Console.WriteLine();
                Console.WriteLine("Usage: ./{0} WUClient [ZipCode] [Endpoint]", AppDomain.CurrentDomain.FriendlyName);
                Console.WriteLine();
                Console.WriteLine("    ZipCode   The zip code to subscribe. Default is 72622 Nürtingen");
                Console.WriteLine("    Endpoint  Where WUClient should connect to.");
                Console.WriteLine("              Default is tcp://127.0.0.1:5556");
                Console.WriteLine();
                if (args.Length < 1)
                    args = new string[] { "72622", "tcp://127.0.0.1:5556" };
                else
                    args = new string[] { args[0], "tcp://127.0.0.1:5556" };
            }

            string endpoint = args[1];

            // Socket to talk to server
            using (var context = new ZContext())
            using (var subscriber = new ZSocket(context, ZSocketType.SUB))
            {
                string connect_to = args[1];
                Console.WriteLine("I: Connecting to {0}...", connect_to);
                subscriber.Connect(connect_to);

                /* foreach (IPAddress address in WUProxy_GetPublicIPs())
                    {
                        var epgmAddress = string.Format("epgm://{0};239.192.1.1:8100", address);
                        Console.WriteLine("I: Connecting to {0}...", epgmAddress);
                        subscriber.Connect(epgmAddress);
                    }
                } */

                // Subscribe to zipcode
                string zipCode = args[0];
                Console.WriteLine("I: Subscribing to zip code {0}...", zipCode);
                subscriber.Subscribe(zipCode);

                // Process 10 updates
                int i = 0;
                long total_temperature = 0;
                for (; i < 20; ++i)
                {
                    using (var replyFrame = subscriber.ReceiveFrame())
                    {
                        string reply = replyFrame.ReadString();

                        Console.WriteLine(reply);
                        total_temperature += Convert.ToInt64(reply.Split(' ')[1]);
                    }
                }
                Console.WriteLine("Average temperature for zipcode '{0}' was {1}°", zipCode, (total_temperature / i));
            }
        }
开发者ID:ChenXuJasper,项目名称:zguide,代码行数:64,代码来源:wuclient.cs

示例9: _Subscribe

        private static void _Subscribe(ZContext context, IPAddress ipaddress)
        {
            // parse out the hostid from the ipaddress
            var networkId = _ExtractNetworkId(ipaddress);

            using (var listener = new ZSocket(context, ZSocketType.SUB))
            {
                for (var hostId = 1; hostId < 255; hostId++)
                {
                    listener.Connect(string.Format("tcp://{0}.{1}:9000", networkId, hostId));
                }

                listener.Subscribe("");

                while (true)
                {
                    using (var frame = listener.ReceiveFrame())
                    {
                        Console.WriteLine(frame.ReadString());
                    }
                }
            }
        }
开发者ID:dshaneg,项目名称:zmqpoc,代码行数:23,代码来源:Program.cs


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