Constructs a new DgramSocket instance wrapping the provided dgram.Socket.
Adds this socket to the given multicast group.
This is a thin wrapper around dgram.Socket.addMembership, which
configures IP_ADD_MEMBERSHIP for the given multicast group.
OptionalmulticastInterface: stringGets the address information of the bound socket.
The socket's endpoint information or null if the socket is not bound.
Adds this socket to a source-specific multicast group.
This is a thin wrapper around dgram.Socket.addSourceSpecificMembership, configuring source-specific multicast membership for the given source and group.
OptionalmulticastInterface: stringBinds the UDP socket to the specified address and port.
The port to bind to. If not specified, a random available port will be used.
Optionaladdress: stringThe address to bind to. If not specified, the socket will bind to all available interfaces.
Optionaloptions: { exclusive?: boolean; fd?: number }Binding options.
A promise that resolves when the socket is successfully bound.
Closes the UDP socket.
A promise that resolves when the socket is successfully closed.
ProtecteddispatchDispatches an event to all listeners for the given event name.
The event name.
Arguments to pass to listeners.
Removes this socket from the given multicast group.
This is a thin wrapper around dgram.Socket.dropMembership, which
configures IP_DROP_MEMBERSHIP for the given multicast group.
OptionalmulticastInterface: stringRemoves this socket from a source-specific multicast group.
This is a thin wrapper around dgram.Socket.dropSourceSpecificMembership, removing source-specific multicast membership for the given source and group.
OptionalmulticastInterface: stringReturns the size in bytes of the underlying receive buffer.
This is a thin wrapper around dgram.Socket.getRecvBufferSize, which
reads the SO_RCVBUF socket option.
Returns the size in bytes of the underlying send buffer.
This is a thin wrapper around dgram.Socket.getSendBufferSize, which
reads the SO_SNDBUF socket option.
Returns statistics about the underlying send queue.
This wraps dgram.Socket.getSendQueueCount and dgram.Socket.getSendQueueSize into a single object.
Check if a callback is subscribed to a specific event.
The event name.
The callback to check.
References the socket, preventing the process from exiting while the socket is active.
Sends a message to the specified address and port.
The msg argument contains the message to be sent. Depending on its type, different behavior can apply. If msg is a Buffer, any TypedArray or a DataView, the offset and length specify the offset within the Buffer where the message begins and the number of bytes in the message, respectively.
If msg is a String, then it is automatically converted to a Buffer with 'utf8' encoding.
With messages that contain multi-byte characters, offset and length will be calculated with respect to byte length and not the character position. If msg is an array, offset and length must not be specified.
The destination port.
The destination address.
The message to send. This can be a Buffer, TypedArray, or DataView.
Optionaloffset: numberOptional offset in the message buffer to start sending from.
Optionallength: numberOptional number of bytes to send from the message buffer.
A promise that resolves with the number of bytes sent.
Enables or disables sending of broadcast datagrams.
This is a thin wrapper around dgram.Socket.setBroadcast, which
toggles the SO_BROADCAST socket option. When enabled, UDP packets may be
sent to broadcast addresses.
Whether broadcast should be enabled.
Sets the outbound multicast interface.
This is a thin wrapper around dgram.Socket.setMulticastInterface, which controls the default outgoing interface for multicast traffic.
Enables or disables loopback for multicast packets sent from this socket.
This is a thin wrapper around dgram.Socket.setMulticastLoopback,
which toggles the IP_MULTICAST_LOOP socket option.
Sets the time-to-live (TTL) value for multicast packets.
This is a thin wrapper around dgram.Socket.setMulticastTTL, which
configures the IP_MULTICAST_TTL socket option.
Sets the size in bytes of the underlying receive buffer.
This is a thin wrapper around dgram.Socket.setRecvBufferSize, which
sets the SO_RCVBUF socket option.
Sets the size in bytes of the underlying send buffer.
This is a thin wrapper around dgram.Socket.setSendBufferSize, which
sets the SO_SNDBUF socket option.
Sets the unicast time-to-live (TTL) value for outgoing packets.
This is a thin wrapper around dgram.Socket.setTTL, which
configures the IP_TTL socket option.
Optionaloptions: EventDispatcherSubscribeOptionsUnreferences the socket, allowing the process to exit even if the socket is active.
Unsubscribe a callback from a specific event.
The event name.
The callback to remove.
Wait for the next occurrence of a specific event, optionally matching a predicate.
This is a convenience method that subscribes to the dispatcher, waits for the next event that matches the predicate (if provided), and then unsubscribes automatically.
The event name to wait for.
Optionaloptions: EventDispatcherWaitOptions<DgramSocketEvents[K]>Optional settings including predicate and abort signal.
A promise that resolves with the event arguments as an array.
StaticfromCreates a new DgramSocket instance with the specified options.
Optionaloptions: SocketOptions
High-level wrapper around Node.js dgram.Socket | UDP datagram sockets.
This class delegates almost all behavior to an underlying dgram.Socket instance while:
RemoteInfo.Unless explicitly documented otherwise, methods have the same semantics as their counterparts on dgram.Socket.
Example usage: