zmq socket bind fails with: "No such device (addr='tcp://wpan0:5556')" when Thread-network interface should be used

huangapple go评论92阅读模式
英文:

zmq socket bind fails with: "No such device (addr='tcp://wpan0:5556')" when Thread-network interface should be used

问题

我正在创建一个基于Python中的Thread网络的系统。我想要使用pyzmq作为我的消息基础(尤其是PUB/SUB)。
我正在使用Debian GNU/Linux 11(bullseye)上的Raspberry Pi 4,来自Nordic Semiconductor的nRF52840 DK作为我的Thread天线,以及Google的Thread边界路由器实现(OpenThread / OTBR)。

我可以从其他Thread设备ping通这个接口,也可以直接绑定一个套接字来使用它。但是一旦我尝试绑定一个ZMQ套接字,我会收到错误消息“No such device (addr='tcp://wpan0:5556')”。

ZMQ可以毫无问题地绑定到Raspberry Pi的其他接口(例如wlan0eth0)。

我尝试像这样绑定一个ZMQ套接字:

self.ctx = zmq.Context()
self.xpub_sock = self.ctx.socket(zmq.XPUB)
self.xpub_sock.bind("tcp://" + self.ip + ":" + self.subport)

我尝试将wpan0作为self.ip的参数,还尝试过wpan0接口的IPv6地址,两者都导致了相同的错误:

Traceback (most recent call last):
  File "/home/pi/DAHS-MAS/zmqMessagingTest.py", line 35, in <module>
    psp = PubSubProxy("wpan0", "5556", "5555", nodefinder)
  File "/home/pi/DAHS-MAS/proxy.py", line 15, in __init__
    self.xpub_sock.bind("tcp://" + self.ip + ":" + self.subport)
  File "/usr/local/lib/python3.9/dist-packages/zmq/sugar/socket.py", line 302, in bind
    super().bind(addr)
  File "zmq/backend/cython/socket.pyx", line 564, in zmq.backend.cython.socket.Socket.bind
  File "zmq/backend/cython/checkrc.pxd", line 28, in zmq.backend.cython.checkrc._check_rc
zmq.error.ZMQError: No such device (addr='tcp://wpan0:5556')

当我直接在wpan0接口上创建并绑定一个网络套接字时,它可以正常工作,所以我预期ZMQ会毫无问题地处理这个接口。

英文:

I am creating a system based on a Thread-network in Python. I want to use pyzmq as my messaging foundation (especially the PUB/SUB).
I am using a Raspberry Pi 4 with Debian GNU/Linux 11 (bullseye), the Thread Border Router implemantation from Goolge (OpenThread / OTBR) an the nRF52840 DK from Nordic Semiconductor as my Thread-antenna.

I can ping the interface from other Thread-devices and I can use it by directly binding a socket to it. But as soon as I try to bind a ZMQ socket to it, I get the error "No such device (addr=&#39;tcp://wpan0:5556&#39;)".
ZMQ can bind without a problem to other interfaces of the Raspberry Pi (for example wlan0 or eth0)

I tried to bind a ZMQ Socket like this:

self.ctx = zmq.Context()
self.xpub_sock = self.ctx.socket(zmq.XPUB)
self.xpub_sock.bind(&quot;tcp://&quot; + self.ip + &quot;:&quot; + self.subport)

I tried to use wpan0 as a parameter for self.ip and also the IPv6 address of the wpan0 interface, both lead to the same error:

Traceback (most recent call last):
  File &quot;/home/pi/DAHS-MAS/zmqMessagingTest.py&quot;, line 35, in &lt;module&gt;
    psp = PubSubProxy(&quot;wpan0&quot;, &quot;5556&quot;, &quot;5555&quot;, nodefinder)
  File &quot;/home/pi/DAHS-MAS/proxy.py&quot;, line 15, in __init__
    self.xpub_sock.bind(&quot;tcp://&quot; + self.ip + &quot;:&quot; + self.subport)
  File &quot;/usr/local/lib/python3.9/dist-packages/zmq/sugar/socket.py&quot;, line 302, in bind
    super().bind(addr)
  File &quot;zmq/backend/cython/socket.pyx&quot;, line 564, in zmq.backend.cython.socket.Socket.bind
  File &quot;zmq/backend/cython/checkrc.pxd&quot;, line 28, in zmq.backend.cython.checkrc._check_rc
zmq.error.ZMQError: No such device (addr=&#39;tcp://wpan0:5556&#39;)

When I directly create and bind a network socket on the wpan0 interface it works, so I expected that zmq will handle the interface without a problem.

答案1

得分: 0

看起来,我忘记将套接字设置为IPv6,就像这样:

self.xpub_sock.setsockopt(zmq.IPV6, 1)

所以如果有人碰到类似的问题,使用只有IPv6地址的接口,请再次检查是否在创建的套接字上设置了zmq.IPV6常量!

英文:

It seems, I forgot to set the socket to IPv6, like this:

self.xpub_sock.setsockopt(zmq.IPV6, 1)

So if anyone is ever having a similar problem, with an interface that has ONLY IPv6 addresses, check again if you set the zmq.IPV6 constant on your created socket!

huangapple
  • 本文由 发表于 2023年6月19日 02:49:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76502091.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定