NetMQ.Poller.AddSocket C# (CSharp) Method

AddSocket() public method

Add the given socket to this Poller's list.
socket must not be null. socket must not have already been added to this poller. This poller must not have already been disposed.
public AddSocket ( [ socket ) : void
socket [ the ISocketPollable to add to the list
return void
        public void AddSocket([NotNull] ISocketPollable socket)
        {
            if (socket == null)
            {
                throw new ArgumentNullException("socket");
            }

            if (m_sockets.Contains(socket.Socket))
            {
                throw new ArgumentException("Socket already added to poller");
            }

            if (m_disposed)
            {
                throw new ObjectDisposedException("Poller is disposed");
            }

            m_sockets.Add(socket.Socket);

            socket.Socket.EventsChanged += OnSocketEventsChanged;

            m_isDirty = true;
        }

Usage Example

Beispiel #1
0
        static void Main(string[] args)
        {
            using (NetMQContext context = NetMQContext.Create())
            {
                using (WSRouter router = context.CreateWSRouter())
                using (WSPublisher publisher = context.CreateWSPublisher())
                {
                    router.Bind("ws://localhost:80");                    
                    publisher.Bind("ws://localhost:81");

                    router.ReceiveReady += (sender, eventArgs) =>
                    {
                        string identity = router.ReceiveString();
                        string message = router.ReceiveString();

                        router.SendMore(identity).Send("OK");

                        publisher.SendMore("chat").Send(message);
                    };
                        
                    Poller poller = new Poller();
                    poller.AddSocket(router);

                    // we must add the publisher to the poller although we are not registering to any event.
                    // The internal stream socket handle connections and subscriptions and use the events internally
                    poller.AddSocket(publisher);
                    poller.Start();

                }
            }
        }
All Usage Examples Of NetMQ.Poller::AddSocket