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


C# NetMQSocket.Connect方法代码示例

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


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

示例1: NmqMessageSender

 internal NmqMessageSender(Uri serviceUri)
 {
     context = NetMQContext.Create();
     socket = context.CreateRequestSocket();
     var address = string.Format("tcp://{0}:{1}", serviceUri.Host, serviceUri.Port);
     socket.Connect(address);
 }
开发者ID:yonglehou,项目名称:DistributedCommunicationDotNet,代码行数:7,代码来源:NmqMessageSender.cs

示例2: Start

 public void Start()
 {
     poller = new Poller();
     clientSocket = context.CreateDealerSocket();
     clientSocket.ReceiveReady += clientSocket_ReceiveReady;
     clientSocket.Connect(address);
     scheduler = new NetMQScheduler(context, poller);
     Task.Factory.StartNew(poller.Start, TaskCreationOptions.LongRunning);
 }
开发者ID:huoxudong125,项目名称:ZeroMqDemos,代码行数:9,代码来源:Client.cs

示例3: Start

		public void Start ()
		{
			ThrowIfDisposed ();
			nmqPoller = new Poller ();
			nmqClient = nmqContext.CreateRequestSocket ();
			nmqClient.Connect (Address.AbsoluteUri.TrimEnd ('/'));
			nmqScheduler = new NetMQScheduler (nmqContext, nmqPoller);
			Task.Factory.StartNew (() => nmqPoller.Start (), TaskCreationOptions.LongRunning);
		}
开发者ID:nerdshark,项目名称:CSharpReplAddin,代码行数:9,代码来源:CSharpReplServerProxy.cs

示例4: MessageHelper

		public MessageHelper(string address, string topic)
		{
			_context = NetMQContext.Create();
			_subscribeSocket = _context.CreateSubscriberSocket();
			_subscribeSocket.Connect(address);
			_subscribeSocket.ReceiveReady += SubscribeSocketOnReceiveReady;
			_subscribeSocket.Subscribe(topic);
			_poller = new Poller();
			_poller.AddSocket(_subscribeSocket);
			Task.Factory.StartNew(_poller.Start);
		}
开发者ID:jacob-adams,项目名称:message-result-client,代码行数:11,代码来源:MessageHelper.cs

示例5: Start

        public TestReciever Start()
        {
            _context = NetMQContext.Create();
            _socket = _context.CreatePullSocket();
            _socket.Connect(_publisherAddress);

            Task.Run(() =>
            {
                Recieve();
            });

            return this;
        }
开发者ID:Grovesy,项目名称:Feeds,代码行数:13,代码来源:TestReciever.cs

示例6: Subscriber

        public Subscriber(params string[] messageKeys)
        {
            if (messageKeys != null && messageKeys.Length > 0)
                subscribeTo.AddRange(messageKeys.ToList());

            context = NetMQContext.Create();
            server = context.CreateSubscriberSocket();
            server.Connect("tcp://127.0.0.1:5003");

            subscribeTo.ForEach(server.Subscribe);

            Thread.Sleep(500);
        }
开发者ID:victorpictor,项目名称:Kan,代码行数:13,代码来源:Subscriber.cs

示例7: Start

    // initialized sprites
    void Start()
    {
        AsyncIO.ForceDotNet.Force();
        calImages = new Sprite[10];
        calImages[0] = Resources.Load<Sprite>("notargets");
        calImages[1] = Resources.Load<Sprite>("targetTL");
        calImages[2] = Resources.Load<Sprite>("targetTM");
        calImages[3] = Resources.Load<Sprite>("targetTR");
        calImages[4] = Resources.Load<Sprite>("targetML");
        calImages[5] = Resources.Load<Sprite>("targetMM");
        calImages[6] = Resources.Load<Sprite>("targetMR");
        calImages[7] = Resources.Load<Sprite>("targetBL");
        calImages[8] = Resources.Load<Sprite>("targetBM");
        calImages[9] = Resources.Load<Sprite>("targetBR");

        calCount = 0;
        curCount = 0;
        gameObject.GetComponent<Image> ().sprite = calImages [calCount];
        //max coords 1180*564
        transX = 0;
        transY = 0;
        targetPrefab = GameObject.FindGameObjectWithTag ("RaycastTarget");
        targetPrefab.SetActive (false);
        targetPrefab.layer = 2;//ignore raycast layer
        isVisible = false;

        AsyncIO.ForceDotNet.Force();
        //setup sockets
        //hangs????
        //http://forum.unity3d.com/threads/netmq-basic.298104/
        //must compile myself
        //https://github.com/zeromq/netmq/issues/98
        context = NetMQContext.Create ();
        server = context.CreatePublisherSocket ();
        server.Bind("tcp://127.0.0.1:5556");
        client = context.CreateSubscriberSocket ();
        client.Connect("tcp://127.0.0.1:5556");
        client.Subscribe ("coord");
        Debug.Log (System.Environment.Version);
        /*server.SendMore("coord").Send ("200 200");
        string top = client.ReceiveString ();
        string message = client.ReceiveString ();
        Debug.Log (message);
        string[] coord = message.Split ();
        transX = int.Parse (coord [0]);
        transY = int.Parse (coord [1]);*/
    }
开发者ID:VirtualVision,项目名称:VirtualVisionUnity,代码行数:48,代码来源:HUDPluginImageScript.cs

示例8: NetMQScheduler

        public NetMQScheduler(NetMQContext context, Poller poller = null)
        {
            m_context = context;
            if (poller == null)
            {
                m_ownPoller = true;
                m_poller = new Poller();
            }
            else
            {
                m_ownPoller = false;
                m_poller = poller;
            }

            m_tasksQueue = new ConcurrentQueue<Task>();
            m_syncObject = new object();

            m_schedulerId = Interlocked.Increment(ref s_schedulerCounter);

            m_address = string.Format("{0}://scheduler-{1}", NetMQ.zmq.Address.InProcProtocol, m_schedulerId);

            m_serverSocket = context.CreatePullSocket();
            m_serverSocket.Options.Linger = TimeSpan.Zero;
            m_serverSocket.Bind(m_address);

            m_currentMessageHandler = OnMessageFirstTime;

            m_serverSocket.ReceiveReady += m_currentMessageHandler;

            m_poller.AddSocket(m_serverSocket);

            m_clientSocket = m_context.CreatePushSocket();
            m_clientSocket.Connect(m_address);

            m_schedulerThread = new ThreadLocal<bool>(() => false);

            if (m_ownPoller)
            {
                Task.Factory.StartNew(m_poller.Start, TaskCreationOptions.LongRunning);
            }
        }
开发者ID:EugenDueck,项目名称:netmq,代码行数:41,代码来源:NetMQScheduler.cs

示例9: NetMQScheduler

        /// <summary>
        /// Create a new NetMQScheduler object within the given context, and optionally using the given poller.
        /// </summary>
        /// <param name="context">the NetMQContext to create this NetMQScheduler within</param>
        /// <param name="poller">(optional)the Poller for this Net to use</param>
        public NetMQScheduler([NotNull] NetMQContext context, [CanBeNull] Poller poller = null)
        {
            if (poller == null)
            {
                m_ownPoller = true;
                m_poller = new Poller();
            }
            else
            {
                m_ownPoller = false;
                m_poller = poller;
            }

            m_tasksQueue = new ConcurrentQueue<Task>();
            m_syncObject = new object();

            var schedulerId = Interlocked.Increment(ref s_schedulerCounter);

            var address = string.Format("{0}://scheduler-{1}", Address.InProcProtocol, schedulerId);

            m_serverSocket = context.CreatePullSocket();
            m_serverSocket.Options.Linger = TimeSpan.Zero;
            m_serverSocket.Bind(address);

            m_currentMessageHandler = OnMessageFirstTime;

            m_serverSocket.ReceiveReady += m_currentMessageHandler;

            m_poller.AddSocket(m_serverSocket);

            m_clientSocket = context.CreatePushSocket();
            m_clientSocket.Connect(address);

            m_schedulerThread = new ThreadLocal<bool>(() => false);

            if (m_ownPoller)
            {
                m_poller.PollTillCancelledNonBlocking();
            }
        }
开发者ID:bbqchickenrobot,项目名称:netmq,代码行数:45,代码来源:NetMQScheduler.cs

示例10: Main

        static void Main(string[] args)
        {
            using (var context = NetMQContext.Create())
            {
                worker = context.CreateRequestSocket();

                var randomizer = new Random(DateTime.Now.Millisecond);
                Guid guid = Guid.NewGuid();
                worker.Options.Identity = Encoding.Unicode.GetBytes(guid.ToString());
                worker.ReceiveReady += WorkerOnReceiveReady;
                worker.Connect(SERVER_ENDPOINT);

                Console.WriteLine("W: {0} worker ready", guid);
                worker.Send(Encoding.Unicode.GetBytes(LRU_READY));

                var cycles = 0;
                while (true)
                {
                    cycles += 1;
                    if (cycles > 3 && randomizer.Next(0, 5) == 0)
                    {
                        Console.WriteLine("W: {0} simulating a crash", guid);
                        System.Threading.Thread.Sleep(5000);
                        //break;
                    }
                    else if (cycles > 3 && randomizer.Next(0, 5) == 0)
                    {
                        Console.WriteLine("W: {0} simulating CPU overload", guid);
                        System.Threading.Thread.Sleep(3000);
                    }
                    Console.WriteLine("W: {0} normal reply", guid);

                    worker.Poll(TimeSpan.FromMilliseconds(1000));
                }

            }
        }
开发者ID:EugenDueck,项目名称:netmq,代码行数:37,代码来源:Program.cs

示例11: NetMQScheduler

        private NetMQScheduler(Poller poller, PushSocket pushSocket, PullSocket pullSocket)
        {
            if (poller == null)
            {
                m_ownPoller = true;
                m_poller = new Poller();
            }
            else
            {
                m_ownPoller = false;
                m_poller = poller;
            }

            var address = string.Format("{0}://scheduler-{1}",
                Address.InProcProtocol,
                Interlocked.Increment(ref s_schedulerCounter));

            m_serverSocket = pullSocket;
            m_serverSocket.Options.Linger = TimeSpan.Zero;
            m_serverSocket.Bind(address);

            m_currentMessageHandler = OnMessageFirstTime;

            m_serverSocket.ReceiveReady += m_currentMessageHandler;

            m_poller.AddSocket(m_serverSocket);

            m_clientSocket = pushSocket;
            m_clientSocket.Connect(address);

            m_isSchedulerThread = new ThreadLocal<bool>(() => false);

            if (m_ownPoller)
            {
                m_poller.PollTillCancelledNonBlocking();
            }
        }
开发者ID:hdxhan,项目名称:netmq,代码行数:37,代码来源:NetMQScheduler.cs

示例12: Connect

        /// <summary>
        ///     connects to the broker, if a socket already exists it will be disposed and
        ///     a new socket created and connected (Linger is set to 1)
        ///     The Client connects to broker using a DEALER socket
        /// </summary>
        private void Connect()
        {
            if (!ReferenceEquals(m_client, null))
            {
                m_poller.Remove(m_client);
                m_client.Dispose();
            }
               
            m_client = new DealerSocket();

            // sets a low linger to avoid port exhaustion, messages can be lost since it'll be sent again
            m_client.Options.Linger = m_lingerTime;

            if (m_identity != null)
                m_client.Options.Identity = m_identity;

            // set timeout timer to reconnect if no message is received during timeout
            m_timer.EnableAndReset(); 

            // attach the event handler for incoming messages
            m_client.ReceiveReady += OnProcessReceiveReady;
            m_poller.Add(m_client);

            // TODO Define HighWaterMark!?
            m_client.Connect(m_brokerAddress);

            m_connected = true;

            Log($"[CLIENT] connecting to broker at {m_brokerAddress}");
        }
开发者ID:GrabCAD,项目名称:netmq,代码行数:35,代码来源:MDPClientAsync.cs

示例13: Connect

        /// <summary>
        /// Connect or re-connect to the broker.
        /// </summary>
        private void Connect()
        {
            // if the socket exists dispose it and re-create one
            if (!ReferenceEquals(m_worker, null))
            {
                m_worker.Unbind(m_brokerAddress);
                m_worker.Dispose();
            }

            m_worker = m_ctx.CreateDealerSocket();
            // set identity if provided
            if (m_identity != null && m_identity.Length > 0)
                m_worker.Options.Identity = m_identity;

            // hook up the received message processing method before the socket is connected
            m_worker.ReceiveReady += ProcessReceiveReady;

            m_worker.Connect(m_brokerAddress);

            Log(string.Format("[WORKER] connected to broker at {0}", m_brokerAddress));

            // signal that worker is connected
            m_connected = true;
            // send READY to broker since worker is connected
            Send(MDPCommand.Ready, m_serviceName, null);
            // reset liveliness to active broker
            m_liveliness = _HEARTBEAT_LIVELINESS;
            // set point in time for next heartbeat
            m_heartbeatAt = DateTime.UtcNow + HeartbeatDelay;
        }
开发者ID:bbqchickenrobot,项目名称:netmq,代码行数:33,代码来源:MDPWorker.cs

示例14: Connect

 public void Connect()
 {
     if (context == null)
     {
         context = NetMQContext.Create();
     }
     if (socket != null)
     {
         throw new NetMQException("Attempt to set socket that was already defined. This would prevent successful dispose of the context later on (since we can no longer close all sockets).");
     }
     socket = context.CreateRequestSocket();
     socket.Options.Linger = new TimeSpan(0, 0, 0, 1);
     socket.Connect("tcp://" + host + ":" + port);
 }
开发者ID:MischaJ,项目名称:mmi-csharp,代码行数:14,代码来源:MmiModelClient.cs

示例15: Connect

 private void Connect()
 {
     _context = NetMQContext.Create();
     _socket = _context.CreatePullSocket();
     _socket.Connect(_publisherAddress);
 }
开发者ID:Grovesy,项目名称:Feeds,代码行数:6,代码来源:FeedReciever.cs


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