@gibme/multicast
    Preparing search index...

    Class MulticastSocket

    Hierarchy

    • EventEmitter
      • MulticastSocket
    Index

    Constructors

    • Protected

      Creates a new instance of a MulticastSocket

      Parameters

      • options: MulticastSocket.Options
      • type: SocketType
      • interfaces: (Address6 | Address4)[]
      • addresses: string[]
      • multicastSocket: Socket
      • unicastSockets: Map<string, Socket>

      Returns MulticastSocket

    Properties

    addresses: string[]
    interfaces: (Address6 | Address4)[]
    multicastSocket: Socket
    type: SocketType
    unicastSockets: Map<string, Socket>

    Accessors

    • get addressInfo(): AddressInfo[]

      Returns an array of objects containing the address information all the underlying sockets.

      For UDP sockets, each object will contain address, family, and port properties.

      Returns AddressInfo[]

    Methods

    • Close the underlying socket and stop listening for data on it. If a callback is provided, it is added as a listener for the 'close' event.

      Returns Promise<void>

    • Closes the underlying socket(s) and cleans all event listeners from the instance

      Returns Promise<void>

    • Alias for emitter.removeListener().

      Parameters

      • event: "close"
      • listener: (local: AddressInfo) => void

      Returns this

      v10.0.0

    • Parameters

      • event: "connect"
      • listener: (local: AddressInfo) => void

      Returns this

    • Parameters

      • event: "error"
      • listener: (error: Error, local?: AddressInfo) => void

      Returns this

    • Parameters

      • event: "message"
      • listener: (
            message: Buffer,
            local: AddressInfo,
            remote: RemoteInfo,
            fromSelf: boolean,
        ) => void

      Returns this

    • Adds the listener function to the end of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times.

      server.on('connection', (stream) => {
      console.log('someone connected!');
      });

      Returns a reference to the EventEmitter, so that calls can be chained.

      By default, event listeners are invoked in the order they are added. The emitter.prependListener() method can be used as an alternative to add the event listener to the beginning of the listeners array.

      import { EventEmitter } from 'node:events';
      const myEE = new EventEmitter();
      myEE.on('foo', () => console.log('a'));
      myEE.prependListener('foo', () => console.log('b'));
      myEE.emit('foo');
      // Prints:
      // b
      // a

      Parameters

      • event: "close"
      • listener: (local: AddressInfo) => void

        The callback function

      Returns this

      v0.1.101

    • Parameters

      • event: "connect"
      • listener: (local: AddressInfo) => void

      Returns this

    • Parameters

      • event: "error"
      • listener: (error: Error, local?: AddressInfo) => void

      Returns this

    • Parameters

      • event: "message"
      • listener: (
            message: Buffer,
            local: AddressInfo,
            remote: RemoteInfo,
            fromSelf: boolean,
        ) => void

      Returns this

    • Adds a one-time listener function for the event named eventName. The next time eventName is triggered, this listener is removed and then invoked.

      server.once('connection', (stream) => {
      console.log('Ah, we have our first user!');
      });

      Returns a reference to the EventEmitter, so that calls can be chained.

      By default, event listeners are invoked in the order they are added. The emitter.prependOnceListener() method can be used as an alternative to add the event listener to the beginning of the listeners array.

      import { EventEmitter } from 'node:events';
      const myEE = new EventEmitter();
      myEE.once('foo', () => console.log('a'));
      myEE.prependOnceListener('foo', () => console.log('b'));
      myEE.emit('foo');
      // Prints:
      // b
      // a

      Parameters

      • event: "close"
      • listener: (local: AddressInfo) => void

        The callback function

      Returns this

      v0.3.0

    • Parameters

      • event: "connect"
      • listener: (local: AddressInfo) => void

      Returns this

    • Parameters

      • event: "error"
      • listener: (error: Error, local?: AddressInfo) => void

      Returns this

    • Parameters

      • event: "message"
      • listener: (
            message: Buffer,
            local: AddressInfo,
            remote: RemoteInfo,
            fromSelf: boolean,
        ) => void

      Returns this

    • By default, binding a socket will cause it to block the Node.js process from exiting as long as the socket is open. The socket. unref() method can be used to exclude the socket from the reference counting that keeps the Node.js process active. The socket ref() method adds the socket back to the reference counting and restores the default behavior.

      Returns void

    • Sends the specified message via the socket

      By default, the packet will be sent out to the multicast group address from all the underlying unicast sockets.

      If options.useMulticastSocket is set, the packet will only be sent out via the underlying multicast socket; however, the behavior for this is undefined if the options.srcAddress is not also set as it may not be broadcasted on all interfaces as you might expect if the instance is also bound to 0.0.0.0 or ::.

      If options.srcAddress is set, the packet will only be sent out via the corresponding unicast socket.

      If options.dstAddress is set, the packet will be sent via unicast to the specified address.

      If any failures are returned upon attempting to send, they will be returned as an array of those errors.

      Parameters

      Returns Promise<Error[]>

      Error if the specified options.srcAddress is not available

    • Sets or clears the IP_MULTICAST_LOOP socket option. When set to true, our own multicast packets will also be received on the local interface.

      Parameters

      • loopback: boolean

      Returns void

    • Sets the TTL of the socket

      Parameters

      • ttl: number

      Returns void

    • By default, binding a socket will cause it to block the Node.js process from exiting as long as the socket is open. The socket unref() method can be used to exclude the socket from the reference counting that keeps the Node.js process active, allowing the process to exit even if the socket is still listening

      Returns void

    • Creates a new multicast socket using the supplied options.

      When creating an instance, the underlying socket(s) are created, the events are mapped through to the instance of this class, the sockets are bound, and we're off to the races.

      Note: the socket type (udp4 or udp6) is automatically detected based upon the type of multicastGroup supplied in the constructor options.

      Additionally, the interface supplied can be one of IPv4, IPv6, interface names, or undefined.

      If interface is undefined, we will listen on all available interfaces (similar to binding to 0.0.0.0 or ::)

      If interface is an interface name, we will listen to all addresses assigned to that interface

      Parameters

      Returns Promise<MulticastSocket>