Can';t获取ZeroMQ python绑定以通过IPC接收消息
我试图通过IPC实现发布/订阅。如果我更改了下面的代码,以便订阅服务器绑定到“tcp://*:5000”,而发布服务器连接到”tcp://localhost:5000“它可以工作,但我无法让它在IPC上工作。我做错了什么 订阅服务器.pyCan';t获取ZeroMQ python绑定以通过IPC接收消息,python,ipc,zeromq,Python,Ipc,Zeromq,我试图通过IPC实现发布/订阅。如果我更改了下面的代码,以便订阅服务器绑定到“tcp://*:5000”,而发布服务器连接到”tcp://localhost:5000“它可以工作,但我无法让它在IPC上工作。我做错了什么 订阅服务器.py import zmq, json def main(): context = zmq.Context() subscriber = context.socket(zmq.SUB) subscriber.bind("ipc://test
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()
最可能的原因是您正在其他目录中运行发布服务器。尝试对管道位置使用绝对路径:ipc:///tmp/test.pipe". 您现在使用它的方式使它与当前工作目录相对。Ohhhh,我明白我的困惑所在。谢谢!:)绝对路径是ipc:///而不是ipc://以防其他人看不到。通常,最可靠的连接是
bind()
s,较少的连接是connect()
s。通常是绑定的服务器。