无法获得ZeroMQ python绑定以通过IPC接收消息

Kit*_*nde 21 python ipc zeromq

我正在尝试通过IPC实现PUB/SUB.如果我改变了下面的代码,以便用户结合"TCP://*:5000"和出版商连接到"TCP://本地主机:5000"它的工作原理,但我不能让它工作在IPC.我究竟做错了什么?

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()
Run Code Online (Sandbox Code Playgroud)

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()
Run Code Online (Sandbox Code Playgroud)

小智 24

最可能的原因是您在不同的目录中运行发布者.尝试使用管道位置的绝对路径:"ipc:///tmp/test.pipe".您现在使用它的方式使其与当前工作目录相关.

  • 对于绝对路径,它是ipc:///而不是ipc://,以防其他人看不到它. (6认同)