gpt4 book ai didi

linux - SO_REUSEPORT 与组播 UDP 的使用

转载 作者:太空宇宙 更新时间:2023-11-04 11:20:49 26 4
gpt4 key购买 nike

在关于 SO_REUSEPORT 的讨论中,以下问题已发布到 reddit ,却无人接听。我想知道 Stack Overflow 是否知道答案。

Can anyone tell me how this interacts with multicast?

I've got an application where the program should listen to multicast UDP messages, and this program may be started multiple times on the same computer. When a message comes it, all listening processes should get it.

I've noticed that on Linux, it works fine if I don't set SO_REUSEPORT, and if I understand correctly, setting SO_REUSEPORT may be the wrong thing to do -- I don't want UDP messages distributed between the processes, I want all processes to get a copy. However, on OS X, the second execution of the program fails to find a free port unless SO_REUSEPORT is set.

tl;dr: Is it expected to set SO_REUSEPORT when using multicast?

最佳答案

通过 SO_REUSEPORT,可以将多个套接字绑定(bind)到同一个端口和地址。唯一的要求是早期的套接字必须设置此选项。因此,如果我们想要两个套接字,sock1 和 sock2 绑定(bind)到同一个端口(和地址),那么只有当 sock1 和 sock2 都设置了 SO_REUSEPORT 时,s2 才能重用端口/地址。关于多播,如果 sock1 和 sock2 都是同一个多播组的接收者,那么它们都会得到一份数据副本。

您可能会发现此答案有帮助:Socket options SO_REUSEADDR and SO_REUSEPORT, how do they differ? Do they mean the same across all major operating systems?

关于linux - SO_REUSEPORT 与组播 UDP 的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18443004/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com