【问题标题】:Can't get ZeroMQ python bindings to receive messages over IPC无法让 ZeroMQ python 绑定通过 IPC 接收消息
【发布时间】:2011-06-30 22:29:59
【问题描述】:

我正在尝试通过 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()

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

【问题讨论】:

  • 一般情况下,bind()s 连接最可靠,connect()s 连接越少。通常服务器是绑定的。

标签: python ipc zeromq


【解决方案1】:

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

【讨论】:

  • 哦,我明白我的困惑在哪里了。谢谢! :)
  • 绝对路径是 ipc:/// 而不是 ipc://,以防其他人看不到。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多