Python 酒吧酒吧只在一个方向工作

Python 酒吧酒吧只在一个方向工作,python,raspberry-pi,zeromq,raspbian,pyzmq,Python,Raspberry Pi,Zeromq,Raspbian,Pyzmq,因此,我正在使用ZeroMQ的python绑定,试图为一个art项目向网络上的几个raspberry PI发送消息。问题是我没有收到任何关于树莓派的消息。更糟糕的是,我可以: 从raspberry pi发布消息并在我的笔记本电脑(osx)上接收 REQ/REP模型在两个方向上工作(osx->RPI和RPI->osx) 我认为这与两台设备上的防火墙有关,我在两台设备上都禁用了防火墙。不走运 有人有什么想法吗?这是我的密码: ZMQ出版商 ZMQ用户 解决了。有两个问题: 首先,因为我使用的是p

因此,我正在使用ZeroMQ的python绑定,试图为一个art项目向网络上的几个raspberry PI发送消息。问题是我没有收到任何关于树莓派的消息。更糟糕的是,我可以:

  • 从raspberry pi发布消息并在我的笔记本电脑(osx)上接收
  • REQ/REP模型在两个方向上工作(osx->RPI和RPI->osx)
我认为这与两台设备上的防火墙有关,我在两台设备上都禁用了防火墙。不走运

有人有什么想法吗?这是我的密码:

ZMQ出版商

ZMQ用户


解决了。有两个问题:

首先,因为我使用的是python3,所以我必须确保在更新/安装python模块时使用的是pip-3.2命令


第二,在我的笔记本电脑上,我使用的是pyzmq 14.6.0,在PI上使用的是2.2.0。我已经更新了它,但是使用了pip而不是pip-3.2。一旦我正确地更新了pyzmq,它就如预期的那样工作了

对我来说很好。也许要仔细检查你的ip?不幸的是,这与pyzmq的版本有关。
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()
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()