Repository navigation
Running the Proxy Locally
The SpectREM Web Spectranet emulation requires a WebSocket-to-UDP/TCP proxy server to bridge the browser's network restrictions. Browsers cannot make raw TCP or UDP connections, so the proxy translates WebSocket frames into real network traffic on behalf of the emulator.
The proxy lives in the proxy/ directory at the root of the repository.
- Node.js 18+ (20 recommended)
- npm (comes with Node.js)
cd proxy
npm install
ALLOWED_ORIGINS=http://localhost:3000 ALLOW_PRIVATE=true node udp-proxy.jsThis starts the proxy on ws://localhost:8080 and allows connections from the Vite dev server at http://localhost:3000.
Once the proxy is running, tell the emulator where to find it:
- Open SpectREM Web in your browser (
http://localhost:3000) - Enable Spectranet via Dev > Spectranet
- Open the Spectranet debug window via View > Spectranet
- In the Proxy URL field, enter:
ws://localhost:8080 - Click Apply
The proxy URL is persisted to localStorage, so you only need to set it once.
| Variable | Default | Description |
|---|---|---|
PORT |
8080 |
Port the proxy listens on |
ALLOWED_ORIGINS |
(none — required) | Comma-separated list of allowed origins. Set to http://localhost:3000 for local dev |
ALLOW_PRIVATE |
false |
Set to true to allow connections to private/LAN IP addresses (e.g., a TNFS server on your local network) |
ALLOWED_PORTS |
53,16384,32768 |
Comma-separated destination port allowlist. Default covers DNS (53) and TNFS (16384, 32768). Set to * to allow all ports |
MAX_CONN_PER_IP |
4 |
Max concurrent WebSocket connections per client IP (matches W5100's 4 sockets) |
IDLE_TIMEOUT_MS |
30000 |
Close idle connections after this many milliseconds |
If you have a TNFS server running on your local network (e.g., 192.168.1.50:16384), start the proxy with private IPs allowed:
ALLOWED_ORIGINS=http://localhost:3000 ALLOW_PRIVATE=true node udp-proxy.jsThen configure the Spectranet in the emulator to connect to your TNFS server's IP address as usual — the proxy will relay the traffic.
A Dockerfile is provided for containerised deployment:
cd proxy
docker build -t spectranet-proxy .
docker run -p 8080:8080 \
-e ALLOWED_ORIGINS=http://localhost:3000 \
-e ALLOW_PRIVATE=true \
spectranet-proxyThe proxy accepts WebSocket connections with a path that encodes the protocol, destination IP, and port:
ws://localhost:8080/udp/{dest_ip}/{dest_port} → UDP datagram relay
ws://localhost:8080/tcp/{dest_ip}/{dest_port} → TCP stream relay
When the emulated Spectranet's W5100 chip issues a CONNECT or SEND command, the JavaScript network manager opens a WebSocket to the proxy at the appropriate path. The proxy then:
- For UDP: Creates a UDP socket, forwards each WebSocket message as a UDP datagram, and relays any responses back over the WebSocket
- For TCP: Opens a TCP connection to the destination, bidirectionally streams data between the WebSocket and TCP socket
The proxy includes several safeguards:
- Origin allowlist — only accepts WebSocket upgrades from specified origins
-
Private IP blocking — prevents SSRF by default (disabled with
ALLOW_PRIVATE=true) - Port allowlist — only relays to explicitly allowed destination ports
- Per-IP connection limit — prevents resource exhaustion
- Idle timeout — automatically closes stale connections
"Origin not allowed" errors in proxy logs
Ensure ALLOWED_ORIGINS includes the exact origin of your dev server (e.g., http://localhost:3000 — note http, not https).
Connections to LAN addresses rejected
Set ALLOW_PRIVATE=true when starting the proxy.
Port not allowed errors
Add the destination port to ALLOWED_PORTS (e.g., ALLOWED_PORTS=53,16384,32768,80).
Proxy not reachable from the emulator
Make sure the Proxy URL in the Spectranet window uses ws:// (not wss://) for local development, and that the port matches the PORT environment variable.