Skip to content
/ ws Public
forked from Gavinpub/ws

websocket command line tool

License

Notifications You must be signed in to change notification settings

slytomcat/ws

 
 

Repository files navigation

ws

ws is a simple command line websocket client designed for exploring and debugging websocket servers. ws includes readline-style keyboard shortcuts, persistent history, and colorization.

Example usage recording

Installation

go install github.com/slytomcat/ws@latest

Or download compiled binary (compacted ELF 64-bit LSB executable, x86-64) from assets of releases

Usage

ws URL [flags]

Simply run ws with the destination URL. For security some sites check the origin header. ws will automatically send the destination URL as the origin. If this doesn't work you can specify it directly with the --origin option.

Example of usage with echo server (see below):

$ ws ws://localhost:8080/ws
> {"type": "echo", "payload": "Hello, world"}
< {"type":"echo","payload":"Hello, world"}
> {"type": "broadcast", "payload": "Hello, world"}
< {"type":"broadcast","payload":"Hello, world"}
< {"type":"broadcastResult","payload":"Hello, world","listenerCount":1}
> ^D

Other possible options

Flags:
  -a, --auth string          auth header value, like 'Bearer $TOKEN'
  -b, --bin2text             print binary message as text
  -c, --compression          enable compression
  -f, --filter string        only messages that match regexp will be printed
  -h, --help                 help for ws
  -m, --init string          connection init message
  -k, --insecure             skip ssl certificate check
  -i, --interval duration    send ping each interval (ex: 20s)
  -o, --origin string        websocket origin (default value is formed from URL)
  -p, --pingPong             print out ping/pong messages
  -s, --subprotocal string   sec-websocket-protocal field
  -t, --timestamp            print timestamps for sent and received messages
  -v, --version              print version  

Echo server

Folder echo-server contains a very simple echo server. It allows to establish ws connection and just replay with received messages or send the message to all active connection. Server accept messages in JSON format (like {"type": "echo", "payload": "Hello, world"}).

Only two types of incoming messages are supported:

  • echo - the message replayed to sender only
  • broadcast - the message is sent to all active connection and the result of broadcasting is sent to sender (with message type broadcastResult).

A message with unknown type as well as massage with incorrect JSON will return the error.

build

cd echo-server
./build.sh

usage

echo-server [server_url]

When server_url is not provided then ws://localhost:8080/ws is used.

start

./echo-server ws://localhost:8080/ws

test

ws ws://localhost:8080/ws
> {"type": "echo", "payload": "Hello, world"}
< {"type":"echo","payload":"Hello, world"}
> {"type": "broadcast", "payload": "Hello, world"}
< {"type":"broadcast","payload":"Hello, world"}
< {"type":"broadcastResult","payload":"Hello, world","listenerCount":1}
> ^D

About

websocket command line tool

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 99.1%
  • Shell 0.9%