Datagram transport

UDP4 + UDP6

Use UDP for independent messages that can tolerate loss, duplication, and reordering. Every local endpoint binds its own port.

Different from a stream

No connection

Each UDP endpoint behaves like a small server. There is no persistent client/server connection.

No delivery promise

Packets may be lost, duplicated, or reordered. Add sequence and recovery logic when the application needs it.

One port per endpoint

Two UDP sockets on the same host cannot both own the same address and port in this basic model.

Receiver on port 8000

import ipc from 'node-ipc';

ipc.config.id = 'telemetry';
ipc.config.networkPort = 8000;

ipc.serveNet('udp4', () => {
  ipc.server.on('reading', (data, peer) => {
    console.log(peer.address, peer.port, data);
    ipc.server.emit(peer, 'ack', {sequence: data.sequence});
  });
});

ipc.server.start();

Use 'udp6' for IPv6. The handler receives the decoded message data and the peer address/port needed for a reply.

Sender on port 8001

ipc.config.id = 'sensor';

ipc.serveNet(8001, 'udp4', () => {
  ipc.server.on('ack', data => console.log(data));

  ipc.server.emit(
    {address: '127.0.0.1', port: 8000},
    'reading',
    {sequence: 1, temperature: 21.4}
  );
});

ipc.server.start();

The destination object is required for a targeted datagram. Starting the receiver first avoids dropping the first packet.

When UDP fits

Good fitPoor fit
Telemetry samples where a newer value replaces an older oneFinancial commands that must run exactly once
Audio, video, or real-time game state with application recoveryLarge payloads that invite fragmentation
Discovery on a controlled networkUnauthenticated control traffic on an untrusted network

Datagram checklist

  • Keep messages small enough to avoid IP fragmentation.
  • Add a sequence number when order or staleness matters.
  • Make handlers idempotent if duplicate delivery would hurt.
  • Authenticate application messages; UDP is neither confidential nor authenticated.
  • Rate-limit untrusted senders and do not reflect amplified responses.
  • Assured intentionally refuses UDP because its network contract requires mutually authenticated TLS.