问题描述
我只是好奇。这是API错误吗?当你加入一个组播组时,你不使用该端口,只使用组播地址(IP)作为组播组,对吗?
I am just curious. Is that an API mistake? When you join a multicast group you do NOT use the port, just the multicast address (IP) which is the multicast group, right?
这是一个烦恼吗?是否会使用PORT?
Is that an annoyance of is there ever the case when the PORT will be used?
推荐答案
这个问题会更好地重新表述为'为什么 DatagramSocket.joinGroup()
带一个 SocketAddress
参数,它可以包含一个端口号?'
The question would be better reformulated as 'why does DatagramSocket.joinGroup()
take a SocketAddress
parameter, which can contain a port number?'
忽略 SocketAddress
中的端口号。多播完全根据IP地址定义。我认为使用 SocketAddress
的原因是它可能意味着一个未解析的地址,其中 InetAddress
表示已解析的地址,并且你不能解析多播地址,但不要引用我; - )
The port number in the SocketAddress
is ignored. Multicast is defined entirely in terms of IP addresses. I think the reason for using SocketAddress
is that it can imply an unresolved address, where InetAddress
implies a resolved address, and you can't resolve multicast addresses, but don't quote me ;-)
这篇关于如果端口对多播组无关紧要,为什么DatagramSocket.joinGroup()方法采用SocketAddress?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!