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?
基础教程推荐
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- Struts2 URL 无法访问 2022-01-01
