method Socket.prototype.addMembership
Usage in Deno
import { Socket } from "node:dgram";
Socket.prototype.addMembership(multicastAddress: string,multicastInterface?: string,): void
Tells the kernel to join a multicast group at the given multicastAddress
and multicastInterface
using the IP_ADD_MEMBERSHIP
socket option. If the multicastInterface
argument is not
specified, the operating system will choose
one interface and will add membership to it. To add membership to every
available interface, call addMembership
multiple times, once per interface.
When called on an unbound socket, this method will implicitly bind to a random port, listening on all interfaces.
When sharing a UDP socket across multiple cluster
workers, thesocket.addMembership()
function must be called only once or anEADDRINUSE
error will occur:
import cluster from 'node:cluster'; import dgram from 'node:dgram'; if (cluster.isPrimary) { cluster.fork(); // Works ok. cluster.fork(); // Fails with EADDRINUSE. } else { const s = dgram.createSocket('udp4'); s.bind(1234, () => { s.addMembership('224.0.0.114'); }); }
void