import { dgram } from "https://deno.land/x/tellojs@v1.0.2/src/deps.ts";
const { Socket } = dgram;
Tells the kernel to join a multicast group at the given multicastAddress
and multicastInterface
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, the
socket.addMembership()
function must be called only once or an
EADDRINUSE
error will occur:
import cluster from 'cluster';
import dgram from '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');
});
}