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


C# ZSocket.SetOption方法代码示例

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


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

示例1: MSReader

		public static void MSReader(string[] args)
		{
			//
			// Reading from multiple sockets
			// This version uses a simple recv loop
			//
			// Author: metadings
			//

			using (var context = new ZContext())
			using (var receiver = new ZSocket(context, ZSocketType.PULL))
			using (var subscriber = new ZSocket(context, ZSocketType.SUB))
			{
				// Connect to task ventilator
				receiver.Connect("tcp://127.0.0.1:5557");

				// Connect to weather server
				subscriber.Connect("tcp://127.0.0.1:5556");
				subscriber.SetOption(ZSocketOption.SUBSCRIBE, "10001 ");

				// Process messages from both sockets
				// We prioritize traffic from the task ventilator
				ZError error;
				ZFrame frame;
				while (true)
				{
					if (null != (frame = receiver.ReceiveFrame(ZSocketFlags.DontWait, out error)))
					{
						// Process task
					}
					else
					{
						if (error == ZError.ETERM)
							return;	// Interrupted
						if (error != ZError.EAGAIN)
							throw new ZException(error);
					}

					if (null != (frame = subscriber.ReceiveFrame(ZSocketFlags.DontWait, out error)))
					{
						// Process weather update
					}
					else
					{
						if (error == ZError.ETERM)
							return;	// Interrupted
						if (error != ZError.EAGAIN)
							throw new ZException(error);
					}

					// No activity, so sleep for 1 msec
					Thread.Sleep(1);
				}
			}
		}
开发者ID:ChenXuJasper,项目名称:zguide,代码行数:55,代码来源:msreader.cs

示例2: MSPoller

		public static void MSPoller(string[] args)
		{
			//
			// Reading from multiple sockets
			// This version uses zmq_poll()
			//
			// Author: metadings
			//

			using (var context = new ZContext())
			using (var receiver = new ZSocket(context, ZSocketType.PULL))
			using (var subscriber = new ZSocket(context, ZSocketType.SUB))
			{
				// Connect to task ventilator
				receiver.Connect("tcp://127.0.0.1:5557");

				// Connect to weather server
				subscriber.Connect("tcp://127.0.0.1:5556");
				subscriber.SetOption(ZSocketOption.SUBSCRIBE, "10001 ");

				var poll = ZPollItem.CreateReceiver();

				// Process messages from both sockets
				ZError error;
				ZMessage msg;
				while (true)
				{
					if (receiver.PollIn(poll, out msg, out error, TimeSpan.FromMilliseconds(64)))
					{
						// Process task
					}
					else
					{
						if (error == ZError.ETERM)
							return;	// Interrupted
						if (error != ZError.EAGAIN)
							throw new ZException(error);
					}

					if (subscriber.PollIn(poll, out msg, out error, TimeSpan.FromMilliseconds(64)))
					{
						// Process weather update
					}
					else
					{
						if (error == ZError.ETERM)
							return;	// Interrupted
						if (error != ZError.EAGAIN)
							throw new ZException(error);
					}
				}
			}
		}
开发者ID:ray-zong,项目名称:zguide,代码行数:53,代码来源:mspoller.cs

示例3: CreateClientAndMonitorSockets

        private void CreateClientAndMonitorSockets(ZContext ctx, IPEndPoint endPoint, string password, out ZSocket client, out ZSocket monitor)
        {
            client = new ZSocket(ctx, ZSocketType.DEALER);
              monitor = new ZSocket(ctx, ZSocketType.PAIR);
              client.Monitor("inproc://monitor-client", ZMonitorEvents.AllEvents);
              monitor.Connect("inproc://monitor-client");

              if (!string.IsNullOrEmpty(password))
              {
            client.PlainUserName = "rcon";
            client.PlainPassword = password;
            client.ZAPDomain = "rcon";
              }

              var ident = new Guid().ToByteArray();
              client.Identity = ident;
              client.SetOption(ZSocketOption.IDENTITY, ident);
              client.Connect("tcp://" + endPoint);
        }
开发者ID:vtchill,项目名称:SteamServerBrowser,代码行数:19,代码来源:QuakeLive.cs

示例4: Start

        /// <summary>
        /// Starts the <see cref="ZeroMQServer"/> synchronously and begins accepting client connections asynchronously.
        /// </summary>
        /// <exception cref="InvalidOperationException">Attempt is made to <see cref="Start()"/> the <see cref="ZeroMQServer"/> when it is running.</exception>
        public override void Start()
        {
            if (CurrentState == ServerState.NotRunning)
            {
                int maxClientConnections, maxQueueSize;

                // Initialize if needed
                if (!Initialized)
                    Initialize();

                // Overwrite config file if max client connections exists in connection string.
                if (m_configData.ContainsKey("maxClientConnections") && int.TryParse(m_configData["maxClientConnections"], out maxClientConnections))
                    MaxClientConnections = maxClientConnections;

                // Overwrite config file if max send queue size exists in connection string.
                if (m_configData.ContainsKey("maxSendQueueSize") && int.TryParse(m_configData["maxSendQueueSize"], out maxQueueSize))
                    m_maxSendQueueSize = maxQueueSize;

                // Overwrite config file if max receive queue size exists in connection string.
                if (m_configData.ContainsKey("maxReceiveQueueSize") && int.TryParse(m_configData["maxReceiveQueueSize"], out maxQueueSize))
                    m_maxReceiveQueueSize = maxQueueSize;

                // Create ZeroMQ Router socket - closest match to IServer implementation
                m_zeroMQServer = new ZSocket(ZContext.Create(), ZSocketType.ROUTER);
                m_zeroMQServer.Identity = ServerID.ToByteArray();
                m_zeroMQServer.SendHighWatermark = m_maxSendQueueSize;
                m_zeroMQServer.ReceiveHighWatermark = m_maxReceiveQueueSize;
                m_zeroMQServer.Immediate = true;
                m_zeroMQServer.SetOption(ZSocketOption.LINGER, 0);
                m_zeroMQServer.SetOption(ZSocketOption.SNDTIMEO, 1000);
                m_zeroMQServer.SetOption(ZSocketOption.RCVTIMEO, -1);
                m_zeroMQServer.SetOption(ZSocketOption.RECONNECT_IVL, -1);
                m_zeroMQServer.IPv6 = (Transport.GetDefaultIPStack() == IPStack.IPv6);
                m_zeroMQServer.Bind(m_configData["server"]);

                // Notify that the server has been started successfully.
                OnServerStarted();

                m_receiveDataThread = new Thread(ReceiveDataHandler);
                m_receiveDataThread.IsBackground = true;
                m_receiveDataThread.Start();
            }
        }
开发者ID:rmc00,项目名称:gsf,代码行数:47,代码来源:ZeroMQServer.cs

示例5: Client

        static int Client(string address, string request)
        {
            // Create
            using (var context = new ZContext())
            using (var requester = new ZSocket(context, ZSocketType.REQ))
            {
                // Connect
                requester.SetOption(ZSocketOption.LINGER, 0);
                requester.Connect(address);

                // Send
                Trace.TraceInformation("Sending request {0}... ", request);
                requester.Send(new ZFrame(request));

                // Receive
                ZPollItem poll = ZPollItem.CreateReceiver();
                ZError error;
                ZMessage reply;
                if (requester.PollIn(poll, out reply, out error, TimeSpan.FromSeconds(2)))
                {
                    using (reply)
                    {
                        string response = reply.PopString();
                        Trace.TraceInformation("Response: {0}", response);
                    }
                }
                else
                {
                    Trace.TraceInformation("Failed to send alarm (timeout)");
                    return 1;
                }
            }
            return 0;
        }
开发者ID:jtanx,项目名称:AppNotifier,代码行数:34,代码来源:Program.cs


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