Skip to content

node:dgram

How Elide supports Node's dgram module: udp4 and udp6 sockets match Node, and --allow-net and --deny-net apply under the sandbox.

On this page

node:dgram matches Node’s dgram for udp4 and udp6 sockets; --allow-net and --deny-net apply under the sandbox.

Example

js
// dgram.mjs
import dgram from "node:dgram";

const server = dgram.createSocket("udp4");
server.on("message", (message, remote) => {
  console.log("received", message.toString(), "from", remote.family);
  server.close();
  client.close();
});
const client = dgram.createSocket("udp4");
server.bind(0, "127.0.0.1", () => {
  client.send("ping", server.address().port, "127.0.0.1");
});
utf-8 · js · Lines: 13

elide run dgram.mjs prints:

text
received ping from IPv4
utf-8 · text · Lines: 1

Reference

Status: Full · Not measured

dgram exports

Socket, createSocket

Was this page helpful?