wasmnet
Networking proxy for browser WASM — bridges WASI socket APIs to real TCP via WebSocket.
Browser WASM cannot do raw TCP/UDP. wasmnet runs server-side and provides real network I/O on behalf of browser WASM programs, with policy controls.
Install
Server (Rust)
Browser Client (npm)
Quick Start
Standalone Server
# Default policy (blocks private IPs, allows public)
# Custom port
# Custom policy file
# No restrictions
Browser Client
import from '@anistark/wasmnet-client';
const client = ;
await client.;
// Outbound TCP
const id = await client.;
client.;
client.;
// Inbound TCP (bind a port)
const listener = await client.;
client.;
Library (Embed in Rust)
use Server;
// Builder API
let server = builder
.host
.port
.policy_file?
.build?;
server.listen.await?;
// Or with graceful shutdown
let = channel;
let server = builder.no_policy.build?;
server.listen_with_shutdown.await?;
// Direct construction
use PolicyConfig;
let addr = "0.0.0.0:9000".parse.unwrap;
let server = from_config;
// Upgrade a single TCP stream (for embedding in existing servers)
use ;
use Arc;
let policy = new;
handle_ws_upgrade.await;
Protocol
JSON messages over a single WebSocket connection.
Requests (browser → server)
| Operation | Fields | Description |
|---|---|---|
connect |
id, addr, port |
Outbound TCP connection |
bind |
id, addr, port |
Bind a local TCP port |
listen |
id, backlog? |
Start accepting connections |
send |
id, data (base64) |
Send data on a socket |
close |
id |
Close a socket or listener |
Events (server → browser)
| Event | Fields | Description |
|---|---|---|
connected |
id |
Connection established |
data |
id, data (base64) |
Data received |
listening |
id, port |
Listener bound |
accepted |
id, conn_id, remote |
New inbound connection |
closed |
id |
Socket closed |
error |
id, msg |
Error occurred |
denied |
id, msg |
Blocked by policy |
Policy
Default policy blocks private IP ranges and allows all public addresses. Customize via TOML:
[]
= ["10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "127.0.0.0/8", "169.254.0.0/16"]
= ["*"]
= "3000-9999"
= 50
= 30
Deny-by-default mode
[]
= ["*"]
= ["api.example.com:443", "*.github.com:443"]
= 5
See policy.example.toml for a full example.
Architecture
)