Index - Node documentation

Usage in Deno

import * as mod from "node:dgram";

The node:dgram module provides an implementation of UDP datagram sockets.

import dgram from 'node:dgram';

const server = dgram.createSocket('udp4');

server.on('error', (err) => {
  console.error(`server error:\n${err.stack}`);
  server.close();
});

server.on('message', (msg, rinfo) => {
  console.log(`server got: ${msg} from ${rinfo.address}:${rinfo.port}`);
});

server.on('listening', () => {
  const address = server.address();
  console.log(`server listening ${address.address}:${address.port}`);
});

server.bind(41234);
// Prints: server listening 0.0.0.0:41234

Classes

c
Socket

Encapsulates the datagram functionality.

Functions

f
createSocket

Creates a dgram.Socket object. Once the socket is created, calling socket.bind() will instruct the socket to begin listening for datagram messages. When address and port are not passed to socket.bind() the method will bind the socket to the "all interfaces" address on a random port (it does the right thing for both udp4 and udp6 sockets). The bound address and port can be retrieved using socket.address().address and socket.address().port.

Interfaces

I
BindOptions
No documentation available
I
RemoteInfo
No documentation available
I
SocketOptions
No documentation available

Type Aliases

T
SocketType
No documentation available