Socket.prototype.addMembership - Node documentation
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 andmulticastInterface using the IP_ADD_MEMBERSHIP socket option. If themulticastInterface 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');
  });
}

Parameters

multicastAddress: string
optional
multicastInterface: string

Return Type

void