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()
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With