Why DatagramSocketImpl joinGroup method takes a NetworkInterface if the socket must have already been bound to it?(如果套接字必须已经绑定到它,为什么 DatagramSocketImpl joinGroup 方法需要一个 NetworkInterface?)
问题描述
只是好奇.那是多余的吗?您还没有绑定到您要使用的网络吗?当您绑定到 0.0.0.0 并且现在只想从接口 X 收听多播数据包时,也许就是这种情况?
Just curious. Is that redundant? Haven't you already bound to the network you want to use? Perhaps that's for the case when you bound to 0.0.0.0 and now want to listen to multicast packets only from interface X?
推荐答案
如果您绑定到 INADDR_ANY(这是正常情况),则加入组 IGMP 消息会通过路由表所说的提供到多播地址的最短路由的任何 NIC 接口发出.在多宿主主机中,您可能需要它通过所有 NIC 出去,因此您可以循环它们依次通过每个 NIC 加入.
If you are bound to INADDR_ANY, which is the normal case, the join-group IGMP message goes out via whichever NIC interface the routing tables say gives the shortest route to the multicast address. In multi-homed hosts you may need it to go out via all NICs, so you loop over them joining via each in turn.
如果您绑定到特定的 NIC,则在加入时指定网络接口是没有意义的.
If you're bound to a specific NIC it doesn't make sense to specify a network interface when joining.
如果您绑定到多播地址本身,因此该套接字只能接收多播,而不是单播 UDP,如果您想通过所有接口加入,您可能需要像 (1) 中那样循环.
If you're bound to the multicast address itself, so that that socket can only receive multicasts, not unicast UDP, you may need to loop as in (1) if you want to join via all interfaces.
这篇关于如果套接字必须已经绑定到它,为什么 DatagramSocketImpl joinGroup 方法需要一个 NetworkInterface?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如果套接字必须已经绑定到它,为什么 DatagramSocketImpl joinGroup 方法需要一个 NetworkInterface?
- 如何使用WebFilter实现授权头检查 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01