WebSocket Tunnel
Learn how to start a WebSocket tunnel with the Portr CLI to expose local real-time apps and WebSocket servers to the public internet.
WebSocket connections use the HTTP protocol for the initial handshake and then switch to use a TCP connection. Because of this, an HTTP tunnel will work perfectly for WebSocket connections.
With a fixed subdomain:
Use the HTTP tunnel command for WebSocket services. The initial HTTP handshake will be handled properly, and the connection will upgrade to WebSocket as expected.
The Portr client-to-server tunnel transport is selected by your server-generated
config. It connects to ssh_url when transport: ssh, or to ws_url when
transport: websocket. Public HTTP and application WebSocket traffic still uses
the normal tunnel URL such as https://realtime-dev.example.com or
wss://realtime-dev.example.com.
How WebSocket Tunneling Works
- Initial handshake: The WebSocket connection starts with an HTTP request containing upgrade headers
- Protocol upgrade: The server responds with a
101 Switching Protocolsstatus - WebSocket connection: The connection upgrades to WebSocket protocol over the existing TCP connection
- Bidirectional communication: Full-duplex communication is established
- Local logging: The inspector records the handshake and WebSocket frame events in the local SQLite dashboard database
Testing WebSocket Connections
You can test your WebSocket tunnel using various tools:
Browser Console
Command Line Tools
Common Use Cases
- Real-time applications: Chat applications, live updates, notifications
- Live data feeds: Stock prices, sensor data, live metrics
- Collaborative tools: Real-time document editing, shared whiteboards
- Gaming: Multiplayer games, real-time game state synchronization