websocat

Websocket proxy, socat-style

``` websocat 1.0.0-alpha Vitaly "_Vi" Shukela vi0oss@gmail.com Connection forwarder from/to web sockets to/from usual sockets, in style of socat

USAGE: websocat [FLAGS] [OPTIONS]

FLAGS: --dump-spec Instead of running, dump the specifiers representation to stdout --exit-on-eof Close a data transfer direction if the other one reached EOF -h, --help Prints help information --long-help Show full help aboput specifiers and examples --oneshot Serve only once --udp-oneshot udp-listen: replies only one packet per client -u, --unidirectional Inhibit copying data from right specifier to left -U, --unidirectional-reverse Inhibit copying data from left specifier to right --unlink Unlink listening UNIX socket before binding to it -V, --version Prints version information -t, --text Send text WebSocket messages instead of binary

OPTIONS: --exec-args ... Arguments for the exec: specifier. Must be the last option, everything after it gets into the exec args list. --protocol Specify Sec-WebSocket-Protocol: header --ws-c-uri URI to use for ws-c: specifier [default: ws://0.0.0.0/]

ARGS: First, listening/connecting specifier. See --long-help for info about specifiers. Second, connecting specifier

Basic examples: Connect stdin/stdout to a websocket: websocat - ws://echo.websocket.org/

Listen websocket and redirect it to a TCP port: websocat ws-l:127.0.0.1:8080 tcp:127.0.0.1:5678

See more examples with the --long-help option

Short list of specifiers (see --long-help): ws:// wss:// - inetd: ws-listen: inetd-ws: tcp: tcp-l: ws-c: autoreconnect: reuse: mirror: threadedstdio: clogged: literal: literalreply: assert: udp-connect: open-async: readfile: writefile: open-fd: unix-connect: unix-listen: unix-dgram: abstract-connect: abstract-listen: exec: sh-c: ```

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

Specify listening part first, unless you want websocat to serve once (like in --oneshot mode).

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.

Pre-built binaries for Linux (usual and musl), Windows, OS X and Android (ARM) are available on the releases page. Most are built without SSL support, so can't connect to secure wss:// websockets, only ws://.

Limitations

Full list of specifiers

(available as --long-help)

location /ws {{ proxy_read_timeout 7d; proxy_send_timeout 7d; #proxy_pass http://localhost:3012; proxy_pass http://unix:/tmp/wstest; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; }}

P.S. Here is oneliner to remove non-blocking mode from terminal's stdin:

perl -we 'use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK); open F, "<&=", 0; my $flags = fcntl(F, F_GETFL, 0); fcntl(F, F_SETFL, $flags & !O_NONBLOCK);'

Planned features

See also