socket.setMulticastInterface(multicastInterface)


本节中对范围的所有引用均指 IPv6 区域索引,由 RFC 4007 定义。 以字符串形式,具有作用域索引的 IP 写成 'IP%scope',其中作用域是接口名称或接口编号。

将套接字的默认传出多播接口设置为选定接口或返回系统接口选择。 multicastInterface 必须是来自套接字家族的 IP 的有效字符串表示形式。

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

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

如果在未绑定的套接字上调用此方法将抛出 EBADF

All references to scope in this section are referring to IPv6 Zone Indices, 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.

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.

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.

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.

This method throws EBADF if called on an unbound socket.