[zeromq-dev] simple publish subscribe not working with zeromq
Karthik Sharma
karthik.sharma at gmail.com
Sun Oct 12 05:23:56 CEST 2014
Hi Justin,
Thanks for the reply.That did work!
I have a follow on question.
I am tying to send the following structure.
msg = {'in_port':in_port,'dst':dst,'actions':actions}
self.push_messages(msg)
However on the recieving side,I can decode the msg using format(msg) but I
can acess the members in the dictionary.
print('flow_mod recieved from ryu-primary {}'.format(flow_mod[in_port]))
---------> flow_mod recieved from ryu-primary {'dst': u'00:00:00:00:00:04',
'actions': [OFPActionOutput(max_len=65509,port=2)], 'in_port': 1}
self.add_flow(datapath, flow_mod[in_port], flow_mod[dst], flow_mod[actions])
-----------> doesn't work? -- gives error "NameError: global name
'in_port' is not defined"
Regards,
Karthik.
On 12 October 2014 12:31, Justin Karneges <justin at affinix.com> wrote:
> 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
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
>
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20141012/e46c6e4b/attachment.htm>
More information about the zeromq-dev
mailing list