wscli
A lightweight and powerful Go command-line tool for interacting with WebSocket servers. Designed for testing, debugging, and scripting, wscli provides functionality similar to wscat but with additional features. This tool is actively developed.
π Installation
Using Docker
$ docker run -it akshaykhairmode/wscli:latest -c "ws://example.com/ws"
Using go install
go install github.com/akshaykhairmode/wscli@latest
Download Prebuilt Binaries
If you donβt have Go installed, download the latest binaries from the Releases Page.
π§ Usage
Connect to a WebSocket server
$ wscli -c ws://localhost:8080/ws
$ wscli -c ws://localhost:8080/ws -H "Authorization: Bearer mytoken" -H "X-Custom: value"
$ wscli -c ws://localhost:8080/ws -x '{"action": "subscribe", "channel": "updates"}'
Send a close message with code 1000 and reason "normal closure"
$ wscli --slash -c ws://localhost:8080/ws
/close 1000 normal closure
Send a binary file
$ wscli --slash -c ws://localhost:8080/ws
/bfile /home/user/test.bin
β¨ Features
- πΉ Native Binaries: Easy installation across systems.
- π€ Piped Input: Send piped input using
| (disables interactive terminal features).
- π¨ Multiple Messages on Connect: Send multiple messages immediately after connecting.
- π Background Execution:
- π History Persistence: Maintain a command history for quick reuse.
- β‘ Command Execution on Connect: Use
-x to execute commands automatically.
- π JSON Pretty Printing: Format JSON responses using
--jspp.
- β¨οΈ Terminal Shortcuts: Supports readline shortcuts like
Ctrl+W (delete word) and Ctrl+R (reverse search). See full list.
- ποΈ Binary File Transfer: Send a file as a binary message.
π Available Flags
| Flag |
Shorthand |
Description |
--auth |
|
HTTP Basic Authentication (username:password). |
--binary |
-b |
Send hex-encoded data. |
--ca |
|
Path to the CA certificate file (optional). |
--cert |
|
Path to the client certificate file (optional). |
--connect |
-c |
WebSocket connection URL. |
--execute |
-x |
Execute a command after connecting. |
--gzipr |
|
Enable gzip decoding (server must send messages as binary). |
--header |
-H |
Custom headers (key:value). |
--help |
-h |
Show help information. |
--jspp |
|
Enable JSON pretty printing. |
--key |
|
Path to the certificate key file (optional). |
--no-check |
-n |
Disable TLS certificate verification. |
--no-color |
|
Disable colored output. |
--origin |
-o |
Specify origin for the WebSocket connection. |
--proxy |
|
Use a proxy URL. |
--response |
-r |
Show HTTP response headers. |
--show-ping-pong |
-P |
Show ping/pong messages. |
--slash |
|
Enable slash commands. |
--sub-protocol |
-s |
Specify a WebSocket sub-protocol. |
--verbose |
-v |
Enable debug logging. |
--version |
-V |
Show version information. |
--wait |
-w |
Wait time after execution (1s, 1m, 1h). |
--perf |
|
Enable performance testing. |
π Slash Commands (Enable via --slash)
| Command |
Description |
/flags |
Show loaded flags. |
/ping |
Send a ping message. |
/pong |
Send a pong message. |
/close |
Send a close message (/close <code> <reason>). |
/bfile |
Send a file (/bfile <file_path>). Max size: 50MB. |
π Load Testing (Enable via --perf)
| Flag |
Description |
--tc |
Total number of connections. |
--lm |
Load message to send. Can use templates defined below. |
--mps |
Messages per second (default: 1). |
--am |
Authentication message. Can use templates defined below. |
--waa |
Wait time after authentication before sending load messages. |
--rups |
Connections ramp-up per second (default: 1). |
Load Message Templates
| Function |
Description |
RandomNumber <max> |
Generates a random number (default: 0β10,000). |
RandomUUID |
Generates a random UUID. |
RandomAlphaNumeric <length> |
Generates a random alphanumeric string (default length: 10). |
Example
$ wscli -c ws://localhost:8080/ws --perf --tc 1000 --lm "hello world {{RandomNumber 50}}" --rups 100 --mps 10
# Flags used:
# --perf (enable performance testing)
# --tc 1000 (create 1000 connections)
# --lm "hello world {{RandomNumber 50}}" (load message, generate a random number from 0 to 50)
# --rups 100 (ramp up 100 connections per second)
# --mps 10 (send 10 messages per second)

π§ Upcoming Features
- WebSocket Listener: Implement a feature to start a WebSocket server.