[zeromq-dev] simple publish subscribe not working with zeromq

Justin Karneges justin at affinix.com
Sun Oct 12 01:31:05 CEST 2014


Hi Karthik,



You need to subscribe to a topic, not merely connect. You can
subscribe to an empty string to receive all messages. E.g.:
sub_socket.setsockopt(zmq.SUBSCRIBE, '')



On Sat, Oct 11, 2014, at 04:16 PM, Karthik Sharma wrote:

I want to establish publish subscribe communication between to
machines.The two machines that I have are
`ryu-primary` and `ryu-secondary`

The steps I follow in each of the machines are as follows.In
the initializer for `ryu-primary` (IP address is
192.168.241.131)

     self.context = zmq.Context()
     self.sub_socket = self.context.socket(zmq.SUB)
     self.pub_socket = self.context.socket(zmq.PUB)
     self.pub_port = 5566
     self.sub_port = 5566


    def establish_zmq_connection(self):
        # Socket to talk to server
        print "Connection to ryu-secondary..."
        self.sub_socket.connect ("tcp://192.168.241.132:%s" %
self.sub_port)

    def listen_zmq_connection(self):
        print('Listen to zmq connection')
        self.pub_socket.bind("tcp://*:%s" % self.pub_port)

    def recieve_messages(self):
        while True:
            try:
                string =
self.sub_socket.recv(flags=zmq.NOBLOCK)
                print('flow mod messages recieved
{}'.format(string))
                return string
            except zmq.ZMQError:
                break

    def push_messages(self,msg):
        self.pub_socket.send("%s" % (msg))


>From ryu-secondary (IP address - 192.168.241.132)

In the initializer

        self.context = zmq.Context()
        self.sub_socket = self.context.socket(zmq.SUB)
        self.pub_socket = self.context.socket(zmq.PUB)
        self.pub_port = 5566
        self.sub_port = 5566


    def establish_zmq_connection(self):
         # Socket to talk to server
         print "Connection to ryu-secondary..."
         self.sub_socket.connect ("tcp://192.168.241.131:%s" %
self.sub_port)

    def listen_zmq_connection(self):
         print('Listen to zmq connection')
         self.pub_socket.bind("tcp://*:%s" % self.pub_port)

    def recieve_messages(self):
        while True:
                try:
                         string =
self.sub_socket.recv(flags=zmq.NOBLOCK)
                         print('flow mod messages recieved
{}'.format(string))
                         return string
                except zmq.ZMQError:
                        break

    def push_messages(self,msg):
         print('pushing message to publish socket')
         self.pub_socket.send("%s" % (msg))


These are the functions that I have.

I am calling
establish_zmq_connections()
push_messages()
from `ryu-secondary`,

But I am not recieving those messages when I am calling
listen_zmq_connection()
recieve_messages()
from `ryu-primary`.

Can someone point out to me what I am doing wrong?

_______________________________________________

zeromq-dev mailing list

[1]zeromq-dev at lists.zeromq.org

[2]http://lists.zeromq.org/mailman/listinfo/zeromq-dev

References

1. mailto:zeromq-dev at lists.zeromq.org
2. http://lists.zeromq.org/mailman/listinfo/zeromq-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20141011/4d2a966a/attachment.htm>


More information about the zeromq-dev mailing list