简体   繁体   English

在树莓上一段时间后,多播UDP停止接收

[英]Multicast UDP stop receiving after a while on a raspberry

I'm trying to make a Raspberry (on Raspbian) receiving UDP multicast messages. 我正在尝试使Raspberry(在Raspbian上)接收UDP多播消息。 I'm using the following code with Python 3: 我在Python 3中使用以下代码:

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(("239.0.0.1", 22700))
mreq = struct.pack("4sl", socket.inet_aton("239.0.0.1"), socket.INADDR_ANY)
sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)

while True:
    data = sock.recv(32).decode("utf8")
    # Do stuff with the received data

This code is working fine, I'm receiving the desired packets but after a while, usually 5 minutes, the sock.recv(32) gets stuck and nothing is received anymore. 这段代码可以正常工作,我正在接收所需的数据包,但是过一会儿(通常是5分钟), sock.recv(32)被卡住了,什么也收不到。 The exact same code works perfectly on my computer, it's been running for more than an hour now, receiving all packets. 完全相同的代码可以在我的计算机上正常工作,现在已经运行了一个多小时,可以接收所有数据包。

Has anyone been confronted to this on a Raspberry ? 有没有人在Raspberry上遇到这个问题? Thanks in advance 提前致谢

This sounds like a typical IGMP problem. 这听起来像是典型的IGMP问题。 These kind of problems are frequent . 这些问题很常见 The typical pattern is that everything works as it should and after some time it stops working. 典型的模式是,一切正常进行,一段时间后停止工作。

Some router or switch along the path stops transporting your multicast packets. 路径上的某些路由器或交换机停止传输多播数据包。 Look for options in the router to enable/disable IGMP snooping and potentially enable/disable different IGMP versions. 在路由器中查找选项以启用/禁用IGMP监听,并可能启用/禁用不同的IGMP版本。 Try a different switch. 尝试使用其他开关。 Avoid exotic hardware (like PowerLine adapters). 避免使用外部硬件(例如PowerLine适配器)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM