Operations 6 min read

Master WebSocket Debugging with websocat: Install, Test, and Proxy

This guide introduces websocat, a Rust‑based command‑line utility for WebSocket, covering installation via package managers or source, basic echo testing, setting up local servers, bidirectional TCP‑WebSocket proxying, secure connections, performance tuning, and integration with systemd and Nginx.

Xiao Liu Lab
Xiao Liu Lab
Xiao Liu Lab
Master WebSocket Debugging with websocat: Install, Test, and Proxy

What is websocat?

websocat is a Rust‑written command‑line utility for the WebSocket protocol, inspired by netcat, socat and curl. It provides a lightweight way to open, test and proxy WebSocket connections.

Installation

Package managers

macOS (Homebrew): brew install websocat
FreeBSD: pkg install websocat

Pre‑compiled binaries

Download the appropriate binary from the GitHub releases page (https://github.com/vi/websocat/releases), extract and run.

Build from source

cargo install websocat

Typical usage examples

Echo test

websocat ws://echo.websocket.org

Type any text; the server echoes it back. Press Ctrl‑D to exit.

Local WebSocket server

websocat -s 8080
# Listening on ws://127.0.0.1:8080/

Connect from another terminal: websocat ws://127.0.0.1:8080/ Multiple clients see each other's messages, forming a simple chat.

Bidirectional TCP ↔ WebSocket proxy

websocat --oneshot -b ws-l:127.0.0.1:1234 tcp:127.0.0.1:22

Wrap SSH traffic in WebSocket, useful for firewall traversal or web‑app integration.

Broadcast to all connected clients

websocat -t ws-l:127.0.0.1:1234 broadcast:mirror:

All clients receive each other's messages.

Secure WebSocket (WSS)

websocat wss://example.com

Skip certificate verification (development only)

websocat -k wss://localhost:8443

Advanced options

Traffic monitoring: prefix the address with log: to see protocol details.

Performance tuning: --async-stdio improves I/O efficiency; -B adjusts buffer size.

Auto‑reconnect: autoreconnect automatically restores broken connections.

JSON‑RPC: communicate with Chrome DevTools protocol, e.g.:

echo '{"id":1,"method":"Page.navigate","params":{"url":"https://example.com"}}' |
websocat --jsonrpc ws://127.0.0.1:9222/devtools/page/XXX

Compression: websocat can use deflate, gzip or zlib to reduce bandwidth.

System integration

Run as a systemd service with socket activation for on‑demand startup.

Example Nginx reverse‑proxy configuration forwarding /ws to a local websocat instance:

location /mywebsocket {
    proxy_pass http://localhost:8080;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DebuggingProxyWebSocketCommand-lineWebsocat
Xiao Liu Lab
Written by

Xiao Liu Lab

An operations lab passionate about server tinkering 🔬 Sharing automation scripts, high-availability architecture, alert optimization, and incident reviews. Using technology to reduce overtime and experience to avoid major pitfalls. Follow me for easier, more reliable operations!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.