Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't get ZeroMQ python bindings to receive messages over IPC

Tags:

I'm trying to achieve PUB/SUB over IPC. If I changed the code below so that the subscriber binds to "tcp://*:5000" and the publisher connects to "tcp://localhost:5000" it works, but I can't get it to work over IPC. What am I doing wrong?

subscriber.py

import zmq, json  def main():     context = zmq.Context()     subscriber = context.socket(zmq.SUB)     subscriber.bind("ipc://test")     subscriber.setsockopt(zmq.SUBSCRIBE, '')     while True:         print subscriber.recv()  if __name__ == "__main__":     main() 

publisher.py

import zmq, json, time  def main():     context = zmq.Context()     publisher = context.socket(zmq.PUB)     publisher.connect("ipc://test")     while True:         publisher.send( "hello world" )         time.sleep( 1 )  if __name__ == "__main__":     main() 
like image 806
Kit Sunde Avatar asked Feb 20 '11 22:02

Kit Sunde


1 Answers

most likely cause is that you are running the publisher in a different directory. Try using absolute path for the pipe location: "ipc:///tmp/test.pipe". The way you are using it now makes it relative to current working directory.

like image 85
Mikko Koppanen Avatar answered Sep 20 '22 06:09

Mikko Koppanen