Workers VPC - TCP connections via connect() over VPC Networks
Key Points
- connect() enables raw TCP to private services
- Works via Tunnel, Mesh, or WAN on‑ramp
- Plaintext TCP only (no TLS)
Summary
Cloudflare Workers VPC Network bindings now support the Socket API connect() to open raw TCP connections to private destinations reachable through a bound Cloudflare Tunnel, Cloudflare Mesh, or Cloudflare WAN on‑ramp. This enables Workers to speak directly to services like Redis, Memcached, MQTT, or any custom TCP protocol over the private network.
Key Points
- Configure a VPC network binding in wrangler (JSONC or TOML) and set remote: true to enable private connectivity.
- At runtime call connect() on the binding (e.g., env.PRIVATE_NETWORK.connect("10.0.1.50:6379")) to obtain a readable/writable socket.
- Example (TypeScript):
const socket = await env.PRIVATE_NETWORK.connect("10.0.1.50:6379");
const writer = socket.writable.getWriter();
await writer.write(new TextEncoder().encode("PING \r\n"));
await writer.close();
return new Response(socket.readable);
- Supported transports: plaintext TCP only (no TLS termination via connect()).
- Works for any TCP-based private service reachable via the bound Tunnel/Mesh/WAN on‑ramp.
- See VPC Networks and Workers Binding API docs for details and security considerations.
Configuration example
JSONC
{
"$schema": "./node_modules/wrangler/config-schema.json",
"vpc_networks": [
{ "binding": "PRIVATE_NETWORK", "network_id": "cf1:network", "remote": true }
]
}
TOML
[[vpc_networks]]
binding = "PRIVATE_NETWORK"
network_id = "cf1:network"
remote = true