我正在尝试通过 IPC 实现 PUB/SUB。如果我更改了下面的代码,以便订阅者绑定到“tcp://*:5000”并且发布者连接到“tcp://localhost:5000”,它可以工作,但我无法让它通过 IPC 工作。我究竟做错了什么?
订阅者.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()
发布者.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()