Usage in Deno
import { Socket } from "node:dgram";
Socket.prototype.setMulticastInterface(multicastInterface: string): void
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.
Example: IPv6 outgoing multicast interface
On most systems, where scope format uses the interface name:
const socket = dgram.createSocket('udp6'); socket.bind(1234, () => { socket.setMulticastInterface('::%eth1'); });
On Windows, where scope format uses an interface number:
const socket = dgram.createSocket('udp6'); socket.bind(1234, () => { socket.setMulticastInterface('::%2'); });
Example: IPv4 outgoing multicast interface
All systems use an IP of the host on the desired physical interface:
const socket = dgram.createSocket('udp4'); socket.bind(1234, () => { socket.setMulticastInterface('10.0.0.2'); });
void