Skip to main content
Socket.prototype.setMulticastInterface - node__dgram.d.ts - Node documentation
method Socket.prototype.setMulticastInterface

Usage in Deno

```typescript import { Socket } from "node:node__dgram.d.ts"; ```
Socket.prototype.setMulticastInterface(multicastInterface: string): void
_All references to scope in this section are referring to [IPv6 Zone Indices](https://en.wikipedia.org/wiki/IPv6_address#Scoped_literal_IPv6_addresses), which are defined by [RFC 4007](https://tools.ietf.org/html/rfc4007). 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: ```js const socket = dgram.createSocket('udp6'); socket.bind(1234, () => { socket.setMulticastInterface('::%eth1'); }); ``` On Windows, where scope format uses an interface number: ```js 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: ```js const socket = dgram.createSocket('udp4'); socket.bind(1234, () => { socket.setMulticastInterface('10.0.0.2'); }); ```

Parameters

multicastInterface: string

Return Type

void