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

Kit Sunde picture Kit Sunde · Feb 20, 2011 · Viewed 7.5k times · Source

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()

Answer

Mikko Koppanen picture Mikko Koppanen · Feb 20, 2011

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.