websocat: Connect to WebSockets from the CLI
websocat ws://host/path opens a WebSocket, wiring stdin to the socket and socket messages to stdout.
websocat is netcat for WebSockets, a single Rust binary. It connects to ws:// or wss:// endpoints and bridges them to stdin/stdout so you can script a handshake check.
What it does
websocat connects to a WebSocket URL, sending lines from stdin as messages and printing received messages to stdout. -t (text mode) treats data as UTF-8 text messages rather than binary. Because it bridges to stdio, you can pipe a message in and capture the reply, then let the connection close.
Common usage
echo '{"type":"ping"}' | websocat -t ws://localhost:8080/socket
websocat -t wss://example.com/ws # secure WebSocket
# one message in, print reply, then exit
echo hello | websocat -n1 -t ws://localhost:8080/echoOptions
| Flag | What it does |
|---|---|
| -t, --text | Send/receive as text (UTF-8) messages |
| -b, --binary | Treat messages as binary |
| -n1, --one-message | Exit after one message each way |
| -H "key: value" | Add an HTTP header to the handshake |
| -k, --insecure | Skip TLS certificate verification (wss) |
In CI
Pipe a single message in and use -n1 so websocat exits after the exchange instead of holding the connection open and hanging the job. For a bare "does the endpoint accept a WebSocket" check, a successful connect and immediate close is enough of a smoke test.
Common errors in CI
websocat: WebSocketError: I/O failure ... Connection refused (os error 111) means no server on that port. websocat: ... HTTP error: 404 Not Found means the WebSocket path is wrong or the endpoint is not upgrading to WebSocket. wss:// against a bad cert gives a TLS verification error; use -k only against a throwaway test server.