所以我正在使用ZeroMQ的python绑定,试图在一个艺术项目的网络上向几个树莓派发送消息。问题是我没有收到有关树莓派的任何消息。更糟糕的是,我可以:
我当时认为它与任一设备上的防火墙有关,我在这两种设备上都禁用了防火墙。没运气。
有人有什么想法吗?这是我的代码:
ZMQ Publisher
import time
import zmq
def main():
port = 5563
# Prepare our context and publisher
context = zmq.Context()
publisher = context.socket(zmq.PUB)
publisher.bind("tcp://*:" + str(port))
while True:
# Write two messages, each with an envelope and content
publisher.send_multipart([b"A", b"We don't want to see this"])
publisher.send_multipart([b"B", b"We would like to see this"])
time.sleep(1)
# We never get here but clean up anyhow
publisher.close()
context.term()
if __name__ == "__main__":
main()
ZMQ订阅者
import zmq
import sys
def main():
ip = sys.argv[1]
port = 5563
string = "tcp://" + ip + ":" + str(port)
# Prepare our context and publisher
context = zmq.Context()
subscriber = context.socket(zmq.SUB)
subscriber.connect(string)
subscriber.setsockopt(zmq.SUBSCRIBE, b"B")
while True:
# Read envelope with address
[address, contents] = subscriber.recv_multipart()
print("[%s] %s" % (address, contents))
# We never get here but clean up anyhow
subscriber.close()
context.term()
if __name__ == "__main__":
main()
答案 0 :(得分:1)
解决。有两个问题:
首先 - 由于我使用的是python3,我必须确保在更新/安装python模块时使用pip-3.2命令
第二 - 在我的笔记本电脑上,我使用的是pyzmq 14.6.0,我在PI上使用了2.2.0。我更新了它,但使用了pip而不是pip-3.2。一旦我正确更新pyzmq它按预期工作。