websocat 1.0.1

Command-line client for web sockets, like netcat/curl/socat for ws://.


Netcat, curl and socat for WebSockets.

Build Status Gitter


Connect to public echo server

$ websocat ws://echo.websocket.org

Serve and connect

A$ websocat -s 1234
Listening on ws://

B$ websocat ws://

Open a tab in Chromium using remote debugging.

$ chromium --remote-debugging-port=9222&
$ curl -sg | grep webSocketDebuggerUrl | cut -d'"' -f4 | head -1
$ printf '{"id":2,"method":"Page.navigate","params":{"url":"%s"}}\n' https://example.com | websocat -n1 --origin --protocol tcp ws://

Proxy TCP connections to WebSocket connections and back.

$ websocat --oneshot -b ws-l: tcp:
$ websocat --oneshot -b tcp-l: ws://
$ nc 1236
SSH-2.0-OpenSSH_7.4p1 Debian-10+deb9u3
Protocol mismatch.

Broadcast all messages between connected WebSocket clients

A$ websocat -t ws-l: broadcast:mirror:
B$ websocat ws://
C$ websocat ws://


  • Connecting to and serving WebSockets from command line.
  • Executing external program and making it communitate to WebSocket using stdin/stdout.
  • Text and binary modes, converting between lines (or null-terminated records) and messages.
  • Inetd mode, UNIX sockets (including abstract namesaced on Linux).
  • Auto-reconnect and connection-reuse modes.
  • Linux, Windows and Mac support, with pre-built executables.
  • Low-level WebSocket clients and servers with overridable underlying transport connection.
  • Buildable by rust starting from v1.23.0.


Vitaly "_Vi" Shukela <vi0oss@gmail.com>
Command-line client for web sockets. Like netcat, but for WebSockets. Designed like socat.

    websocat ws://URL | wss://URL               (simple client)
    websocat -s port                            (simple server)
    websocat [FLAGS] [OPTIONS] <addr1> <addr2>  (advanced mode)

    (some flags are hidden, see --help=long)
    -E, --exit-on-eof                Close a data transfer direction if the other one reached EOF
    -0, --null-terminated            Use \0 instead of \n for linemode
    -1, --one-message                Send and/or receive only one message. Use with --no-close and/or -u/-U.
        --oneshot                    Serve only once. Not to be confused with -1 (--one-message)
    -q                               Suppress all diagnostic messages, except of startup errors
    -s, --server-mode                Simple server mode: specify TCP port or addr:port as single argument
    -S, --strict                     strict line/message mode: drop too long messages instead of splitting them, drop
                                     incomplete lines.
    -u, --unidirectional             Inhibit copying data in one direction
    -U, --unidirectional-reverse     Inhibit copying data in the other direction (or maybe in both directions if
                                     combined with -u)
    -v                               Increase verbosity level to info or further
    -b, --binary                     Send message to WebSockets as binary messages
    -n, --no-close                   Don't send Close message to websocket on EOF
    -t, --text                       Send message to WebSockets as text messages

    (some options are hidden, see --help=long)

    -B, --buffer-size <buffer_size>                Maximum message size, in bytes [default: 65536]
    -H, --header <custom_headers>...
            Add custom HTTP header to websocket client request. Separate header name and value with a colon and
            optionally a single space. Can be used multiple times.
    -h, --help <help>
            See the help.
            --help=short is the list of easy options and address types
            --help=long lists all options and types (see [A] markers)
            --help=doc also shows longer description and examples.
        --origin <origin>                          Add Origin HTTP header to websocket client request
        --protocol <websocket_protocol>            Specify Sec-WebSocket-Protocol: header
        --websocket-version <websocket_version>    Override the Sec-WebSocket-Version value
        --ws-c-uri <ws_c_uri>                      [A] URI to use for ws-c: overlay [default: ws://]

    <addr1>    In simple mode, WebSocket URL to connect. In advanced mode first address (there are many kinds of
               addresses) to use. See --help=types for info about address types. If this is an address for
               listening, it will try serving multiple connections.
    <addr2>    In advanced mode, second address to connect. If this is an address for listening, it will accept only
               one connection.

Basic examples:
  Command-line websocket client:
    websocat ws://echo.websocket.org/
  WebSocket server
    websocat -s 8080
  WebSocket-to-TCP proxy:
    websocat --binary ws-l: tcp:

Partial list of address types:
	ws://           	Insecure (ws://) WebSocket client. Argument is host and URL.
	wss://          	Secure (wss://) WebSocket client. Argument is host and URL.
	ws-listen:      	WebSocket server. Argument is host and port to listen.
	stdio:          	Same as `-`. Read input from console, print to console.
	tcp:            	Connect to specified TCP host and port. Argument is a socket address.
	tcp-listen:     	Listen TCP port on specified address.
	sh-c:           	Start specified command line using `sh -c` or `cmd /C` (depending on platform)
	cmd:            	Start specified command line using `sh -c` (even on Windows)
	readfile:       	Synchronously read a file. Argumen is a file path.
	writefile:      	Synchronously truncate and write a file.
	appendfile:     	Synchronously append a file.
	udp:            	Send and receive packets to specified UDP socket, from random UDP port  
	udp-listen:     	Bind an UDP socket to specified host:port, receive packet
	mirror:         	Simply copy output to input. No arguments needed.
	literalreply:   	Reply with a specified string for each input packet.
	literal:        	Output a string, discard input.
Partial list of overlays:
	broadcast:      	Reuse this connection for serving multiple clients, sending replies to all clients.
	autoreconnect:  	Re-establish underlying connection on any error or EOF


There is a work-in-progress reference document that contains more options and examples.

Technical details

It runs singlethreaded. There is old non-async threaded version in legacy branch of releases prior to 0.5.

IPv6 supported, just use specifiers like ws-l:[::1]:4567

Web socket usage is not obligatory, you can use any specs on both sides.

If you want wss:// server, use socat or nginx in addition to websocat until this function is implemented properly (see nginx.conf sample in the reference document).

Pre-built binaries for Linux (usual and musl), Windows, OS X and Android (ARM) are available on the releases page.


  • Server for wss:// is not implemented (you can workaround it with Nginx or socat).
  • Server mode ignores incomding URL and HTTP headers.

Planned features

  • Driving SSL server websockets (specifying cert and key)
  • Pure Rust version with SSL support?
  • SOCK_SEQPACKET mode for exec:?
  • Add WebRTC's DataChannel to the mix (separate project)?

There are also checkboxes on issues #1 and #5.

Building from source code

  1. Install the Rust tool toolchain
  2. cargo build --release.

See also