No connection
Each UDP endpoint behaves like a small server. There is no persistent client/server connection.
Datagram transport
Use UDP for independent messages that can tolerate loss, duplication, and reordering. Every local endpoint binds its own port.
Each UDP endpoint behaves like a small server. There is no persistent client/server connection.
Packets may be lost, duplicated, or reordered. Add sequence and recovery logic when the application needs it.
Two UDP sockets on the same host cannot both own the same address and port in this basic model.
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.
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.
| Good fit | Poor fit |
|---|---|
| Telemetry samples where a newer value replaces an older one | Financial commands that must run exactly once |
| Audio, video, or real-time game state with application recovery | Large payloads that invite fragmentation |
| Discovery on a controlled network | Unauthenticated control traffic on an untrusted network |