本文介绍了为什么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?

推荐答案


  1. 如果您受到INADDR_ANY的限制,这是正常情况,加入组IGMP消息将通过路由表所说的最短路由到达多播地址的任何NIC接口。在多宿主主机中,你可能需要它通过所有网卡出去,所以你可以依次通过它们循环连接它们。

  1. 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.

如果您已绑定到多播地址本身,那么socket只能接收多播,而不是单播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,如果套接字必须已绑定到它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 23:39