开发者

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

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 subscri开发者_运维问答ber.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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜