socket.setMulticastInterface(multicastInterface)


本节中所有关于作用域的引用都是指 IPv6 区域索引,其由 RFC 4007 定义。以字符串形式表示时,带有作用域索引的 IP 写作 'IP%scope',其中 scope 是接口名称或接口编号。

All references to scope in this section are referring to IPv6 Zone Indexes, which are defined by RFC 4007. In string form, an IP with a scope index is written as 'IP%scope' where scope is an interface name or interface number.

将套接字的默认发送多播接口设置为所选接口,或恢复为系统接口选择。multicastInterface 必须是套接字所属地址族的有效 IP 字符串表示形式。

【Sets the default outgoing multicast interface of the socket to a chosen interface or back to system interface selection. The multicastInterface must be a valid string representation of an IP from the socket's family.】

对于 IPv4 套接字,这应该是为所需物理接口配置的 IP。发送到套接字的所有多播数据包都将通过最近一次成功使用此调用确定的接口发送。

【For IPv4 sockets, this should be the IP configured for the desired physical interface. All packets sent to multicast on the socket will be sent on the interface determined by the most recent successful use of this call.】

对于 IPv6 套接字,multicastInterface 应包括一个作用域以指示接口,如以下示例所示。在 IPv6 中,单独的 send 调用也可以在地址中使用显式作用域,因此只有发送到多播地址且未指定显式作用域的数据包会受到最近一次成功使用此调用的影响。

【For IPv6 sockets, multicastInterface should include a scope to indicate the interface as in the examples that follow. In IPv6, individual send calls can also use explicit scope in addresses, so only packets sent to a multicast address without specifying an explicit scope are affected by the most recent successful use of this call.】

如果在未绑定的套接字上调用此方法,会抛出 EBADF 异常。

【This method throws EBADF if called on an unbound socket.】