# @webvpn/dgram

> Node's dgram module for a web page, with its sockets on a WebVPN relay

Latest version **0.5.0** (published 2026-11-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @webvpn/dgram
pnpm add @webvpn/dgram
yarn add @webvpn/dgram
bun add @webvpn/dgram
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.5.0 |
| Published | 2026-11-27 |
| First published | 2024-08-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 33.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 0 |
| Maintainers | banou26 |
| Keywords | webvpn, dgram, udp, sockets, browser, polyfill |

## Links

- npm: https://www.npmjs.com/package/@webvpn/dgram
- Repository: https://github.com/banou26/webvpn
- Homepage: https://webvpn.dev
- Issues: https://github.com/banou26/webvpn/issues
- npm.io page: https://npm.io/package/@webvpn/dgram

## Dependencies (4)

- [buffer](https://npm.io/package/buffer.md) ^6.0.3
- [events](https://npm.io/package/events.md) ^3.3.0
- [@types/node](https://npm.io/package/@types/node.md) ^25.9.5
- [@webvpn/client](https://npm.io/package/@webvpn/client.md) ^0.5.0

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 0.5.0 (latest) — 2026-11-27
- 0.4.2 — 2026-06-12
- 0.3.7 — 2026-05-16
- 0.3.6 — 2026-05-16
- 0.3.4 — 2026-05-12
- 0.3.3 — 2026-05-12
- 0.3.2 — 2026-05-12
- 0.3.1 — 2026-05-12
- 0.2.0 — 2025-01-01
- 0.0.1 — 2024-08-04

## README

# @webvpn/dgram

Node's `dgram` module for a web page, with every UDP socket on a WebVPN relay through a `@webvpn/client` session.
Code written for Node's `dgram`, such as a DHT or a tracker client, runs in the page as it is.

## Use

```sh
npm install @webvpn/client @webvpn/dgram
```

```js
import { connect as openSession } from '@webvpn/client'
import dgram, { setProvider } from '@webvpn/dgram'

// the session opens at the first socket; a session already open is taken too
setProvider(() => openSession({ url: 'https://relay.example:4433', webSocketUrl: 'wss://relay.example:8443' }))

const socket = dgram.createSocket('udp4')
socket.on('message', (message, remote) => console.log(remote.address, message.toString()))
socket.send('ping', 6881, 'router.example')
```

`createDgram(session)` builds a copy of the module of its own, on that session alone.

## Alias `dgram` to it

With Vite:

```js
export default {
  resolve: { alias: { dgram: '@webvpn/dgram', 'node:dgram': '@webvpn/dgram' } },
}
```

webpack and esbuild have the same setting, `resolve.alias` and `alias`. The package brings the browser builds of
`buffer` and `events` it needs, so the page needs no Node polyfills for it.

## What it does not have

- The `reuseAddr`, `ipv6Only`, buffer size, `lookup` and `signal` options of `createSocket`.
- `setMulticastInterface` and the source specific memberships, which do nothing: the relay has no option for them.
- Host names are looked up through the relay (A records for `udp4`, AAAA for `udp6`), which needs its `DNS` feature.
- `close` is emitted once the relay closed the socket. The relay closing a socket on its own, or the session ending,
  emits `error` when there is a listener for it, then `close`.
- A socket option set before `bind`, or one the relay refuses, emits `error`. The send queue getters answer 0, and the
  buffer size getters the last value set.

---
_Source: https://npm.io/package/@webvpn/dgram · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
