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. Supports quick load testing.
$ docker run -it akshaykhairmode/wscli:latest -c "ws://example.com/ws"
go install github.com/akshaykhairmode/wscli@latest
brew tap akshaykhairmode/tools
brew install akshaykhairmode/tools/wscli
If you donβt have Go installed, download the latest binaries from the Releases Page.
$ 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"}'
$ wscli --slash -c ws://localhost:8080/ws
/close 1000 normal closure
$ wscli --slash -c ws://localhost:8080/ws
/bfile /home/user/test.bin
- πΉ 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:
- Run
wscli
in the background usingnohup
:$ nohup wscli -c ws://localhost/ws -w 1s > nohup.out 2>&1 &
- Redirect output and run in the background:
$ wscli -c ws://localhost/ws >> output.txt & 2>&1
- Run
- π 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) andCtrl+R
(reverse search). See full list. - ποΈ Binary File Transfer: Send a file as a binary message.
- π Load Testing: Perform load tests using the
--perf
flag.
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 ). |
--print-interval |
The interval for printing the output. Default is 1s. | |
--ping-interval |
The interval for pinging to the connected server. Default is 30s. | |
--perf |
Enable performance testing. | |
--std-out |
print the received messages in standard output, default is standard error. |
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. |
Flag | Description | Data Type |
---|---|---|
--tc |
Total number of connections. | unsigned integer |
--lm |
Load message to send. Can use templates defined below. File input supported. | string |
--am |
Authentication message. Can use templates defined below. File input supported. | string |
--mi |
Message interval. (default: 0s). If not set, then lm will be sent only once. | duration |
--waa |
Wait time after authentication before sending load messages. | duration |
--wba |
Wait time before sending auth message to the server | duration |
--rups |
Connections ramp-up per second (default: 1). | unsigned integer |
--outfile |
Do not open the tview output and write the output to file. | string |
--pconfig |
Take perf config from file. Pass the file path here. The format of the file is available here. This will override all other perf flags even if set. | string |
Note: --lm
and --am
also support file input. Provide an absolute path to send messages from a file. The file reading will restart from the first line when EOF is reached. If file is less than 10MB then we store it in memory. "\n" is the delimeter.
Function | Description | Parameters | Data Types |
---|---|---|---|
RandomNum |
Generates a random number between 0 and <max> (default range: 0β10,000). |
<max> (optional) |
Integer |
RandomUUID |
Generates a random UUID. | None | N/A |
RandomAN |
Generates a random alphanumeric string with the specified <length> (default: 10 characters). |
<length> (optional) |
Integer |
UniqSeq |
Generates a unique atomic sequence within a specified <group> . Multiple connections share the same sequence when using the same group. The <start> value sets the initial number (default: 0). If different start values are provided, the first one is used. Examples: - {{UniqSeq "1" 10}} != {{UniqSeq "1" 10}} (Not the same number) - {{UniqSeq "0"}} == {{UniqSeq "1"}} (Different groups generate the same number) |
<group> <start> (optional) |
String Integer |
.Seq |
Generates a sequence starting from 0 for each connection. No shared counters. |
$ wscli -c ws://localhost:8080/ws --perf --tc 1000 --lm "hello world {{RandomNum 50}}" --rups 100 --mi 1s
OR
$ wscli -c ws://localhost:8080/ws --perf --tc 1000 --lm "/tmp/load.txt" --rups 100 --mi 1s
# 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)
# --lm "/tmp/load.txt" (load message, read from file)
# --rups 100 (ramp up 100 connections per second)
# --mi 1s (send 1 message per second)
Normal Output
Perf output:
Perf Verbose output:
Demo