Giter Site home page Giter Site logo

vi / websocat Goto Github PK

View Code? Open in Web Editor NEW
6.5K 68.0 249.0 1.62 MB

Command-line client for WebSockets, like netcat (or curl) for ws:// with advanced socat-like functions

License: MIT License

Rust 97.98% Shell 0.97% Dockerfile 0.19% C 0.87%
websockets websocket-server websocket-client proxy socat rfc-6455 cli command-line command-line-tool netcat

websocat's Introduction

websocat

Netcat, curl and socat for WebSockets.

Gitter image-build

Examples

Connect to public echo server (Ctrl+d to quit)

$ websocat ws://ws.vi-server.org/mirror
123
123
ABC
ABC

$ docker run --rm -ti ghcr.io/vi/websocat:nightly wss://ws.vi-server.org/mirror
123
123
ABC
ABC

Serve and connect

A$ websocat -s 1234
Listening on ws://127.0.0.1:1234/
ABC
123

B$ websocat ws://127.0.0.1:1234/
ABC
123

Open a tab in Chromium using remote debugging.

$ chromium --remote-debugging-port=9222&
$ curl -sg http://127.0.0.1:9222/json/new | grep webSocketDebuggerUrl | cut -d'"' -f4 | head -1
ws://127.0.0.1:9222/devtools/page/A331E56CCB8615EB4FCB720425A82259
$ echo 'Page.navigate {"url":"https://example.com"}' | websocat -n1 --jsonrpc --jsonrpc-omit-jsonrpc ws://127.0.0.1:9222/devtools/page/A331E56CCB8615EB4FCB720425A82259
{"id":2,"result":{"frameId":"A331E56CCB8615EB4FCB720425A82259","loaderId":"EF5AAD19F2F8BB27FAF55F94FFB27DF9"}}

Proxy TCP connections to WebSocket connections and back.

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

Broadcast all messages between connected WebSocket clients

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

(if you like this one, you may actually want https://github.com/vi/wsbroad/ instead)

See moreexamples.md for further examples.

Features

  • Connecting to and serving WebSockets from command line.
  • Executing external program and making it communicate to WebSocket using stdin/stdout.
  • Text and binary modes, converting between lines (or null-terminated records) and messages.
  • Inetd mode, UNIX sockets (including abstract namespaced on Linux).
  • Integration with Nginx using TCP or UNIX sockets.
  • Directly using unauthenticated SOCKS5 servers for connecting to WebSockets and listening WebSocket connection.
  • 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, e.g. calling external program to serve as a transport for websocat (for SSL, proxying, etc.).

Installation

There are multiple options for installing WebSocat. From easy to hard:

Fedora

Copr: sudo dnf copr enable atim/websocat -y && sudo dnf install websocat

FreeBSD

pkg install websocat

Debian / Ubuntu

  • Download a pre-build executable from GitHub releases.
  • Websocat is not yet officially packaged for Debian. Some older versions of Websocat may also have Debian package files available on Github releases.

macOS

Homebrew: brew install websocat

MacPorts: sudo port install websocat

From source

  • Install the Rust toolchain and do cargo install --features=ssl websocat. If something fails with a -sys crate, try without --features=ssl;
  • Build Websocat from source code (see below), then move target/release/websocat somewhere to the PATH.

Pre-built binaries

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

Building from source code

  1. Install the Rust toolchain. Note that Websocat v1 (i.e. the current stable version) may fail to support too new Rust due to its old dependencies which can be broken by e.g. this.
  2. cargo build --release --features=ssl.
  3. Find the executable somewhere under target/, e.g. in target/release/websocat.

Rust versions

Websocat versions Minimal Rust version Maximal Rust version
1.9 - 1.11 1.46 maybe 1.63
1.6 - 1.8 1.34 maybe 1.63
1.3 - 1.5 1.31 1.47?
1.2 1.28 1.47?
1.0-1.1 1.23 1.47?
1.2 ? ?

Note that building with legacy Rust version (e.g. 1.46) may require manually copying Cargo.lock.legacy to Cargo.lock prior to the building.

Early non-async versions of Websocat should be buildable by even older rustc.

Note that old versions of Websocat may misbehave if built by Rust 1.48 or later due to rust-lang/rust#71274.

It may be not a good idea to build v1.x line of Websocat with Rust 1.64 due to [IP address representation refactor]. It may expose previously hidden undefined behaviour in legacy dependencies. (In practice, it seems to just work though - but a lot of time passed since I checked Websocat properly and in detail).

SSL on Android

websocat's wss:// may fail on Android. As a workaround, download certificate bundle, for example, from https://curl.haxx.se/ca/cacert.pem and specify it explicitly:

SSL_CERT_FILE=cacert.pem /data/local/tmp/websocat wss://echo.websocket.org

Or just use --insecure option.

Documentation

Basic usage examples are provided at the top of this README and in --help message. More tricks are described in moreexamples.md.

There is a list of all address types and overlays.

`websocat --help=long` output
websocat 1.13.0
Vitaly "_Vi" Shukela <[email protected]>
Command-line client for web sockets, like netcat/curl/socat for ws://.

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

FLAGS:
        --stdout-announce-listening-ports        [A] Print a line to stdout for each port being listened
        --async-stdio
            [A] On UNIX, set stdin and stdout to nonblocking mode instead of spawning a thread. This should improve
            performance, but may break other programs running on the same console.
        --compress-deflate
            [A] Compress data coming to a WebSocket using deflate method. Affects only binary WebSocket messages.

        --compress-gzip
            [A] Compress data coming to a WebSocket using gzip method. Affects only binary WebSocket messages.

        --compress-zlib
            [A] Compress data coming to a WebSocket using zlib method. Affects only binary WebSocket messages.

        --crypto-reverse
            [A] Swap encryption and decryption operations in `crypto:` specifier - encrypt on read, decrypto on write.

        --dump-spec                              [A] Instead of running, dump the specifiers representation to stdout
    -e, --set-environment
            Set WEBSOCAT_* environment variables when doing exec:/cmd:/sh-c:
            Currently it's WEBSOCAT_URI and WEBSOCAT_CLIENT for
            request URI and client address (if TCP)
            Beware of ShellShock or similar security problems.
    -E, --exit-on-eof                            Close a data transfer direction if the other one reached EOF
        --foreachmsg-wait-read                   [A] Wait for reading to finish before closing foreachmsg:'s peer
        --jsonrpc
            Format messages you type as JSON RPC 2.0 method calls. First word becomes method name, the rest becomes
            parameters, possibly automatically wrapped in [].
        --jsonrpc-omit-jsonrpc                   [A] Omit `jsonrpc` field when using `--jsonrpc`, e.g. for Chromium
        --just-generate-key                      [A] Just a Sec-WebSocket-Key value without running main Websocat
        --lengthprefixed-little-endian
            [A] Use little-endian framing headers instead of big-endian for `lengthprefixed:` overlay.

        --lengthprefixed-skip-read-direction
            [A] Only affect one direction of the `lengthprefixed:` overlay, bypass tranformation for the other one.

        --lengthprefixed-skip-write-direction
            [A] Only affect one direction of the `lengthprefixed:` overlay, bypass tranformation for the other one.

        --linemode-strip-newlines
            [A] Don't include trailing \n or \r\n coming from streams in WebSocket messages

    -0, --null-terminated                        Use \0 instead of \n for linemode
        --no-line                                [A] Don't automatically insert line-to-message transformation
        --no-exit-on-zeromsg
            [A] Don't exit when encountered a zero message. Zero messages are used internally in Websocat, so it may
            fail to close connection at all.
        --no-fixups
            [A] Don't perform automatic command-line fixups. May destabilize websocat operation. Use --dump-spec without
            --no-fixups to discover what is being inserted automatically and read the full manual about Websocat
            internal workings.
        --no-async-stdio                         [A] Inhibit using stdin/stdout in a nonblocking way if it is not a tty
    -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)
        --print-ping-rtts
            Print measured round-trip-time to stderr after each received WebSocket pong.

        --exec-exit-on-disconnect
            [A] Make exec: or sh-c: or cmd: immediately exit when connection is closed, don't wait for termination.

        --exec-sighup-on-stdin-close
            [A] Make exec: or sh-c: or cmd: send SIGHUP on UNIX when input is closed.

        --exec-sighup-on-zero-msg
            [A] Make exec: or sh-c: or cmd: send SIGHUP on UNIX when facing incoming zero-length message.

    -q                                           Suppress all diagnostic messages, except of startup errors
        --reuser-send-zero-msg-on-disconnect
            [A] Make reuse-raw: send a zero-length message to the peer when some clients disconnects.

    -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.

        --timestamp-monotonic                    [A] Use monotonic clock for `timestamp:` overlay
    -k, --insecure                               Accept invalid certificates and hostnames while connecting to TLS
        --udp-broadcast                          [A] Set SO_BROADCAST
        --udp-multicast-loop                     [A] Set IP[V6]_MULTICAST_LOOP
        --udp-oneshot                            [A] udp-listen: replies only one packet per client
        --udp-reuseaddr
            [A] Set SO_REUSEADDR for UDP socket. Listening TCP sockets are always reuseaddr.

        --uncompress-deflate
            [A] Uncompress data coming from a WebSocket using deflate method. Affects only binary WebSocket messages.

        --uncompress-gzip
            [A] Uncompress data coming from a WebSocket using deflate method. Affects only binary WebSocket messages.

        --uncompress-zlib
            [A] Uncompress data coming from a WebSocket using deflate method. Affects only binary WebSocket messages.

    -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)

        --accept-from-fd
            [A] Do not call `socket(2)` in UNIX socket listener peer, start with `accept(2)` using specified file
            descriptor number as argument instead of filename
        --unlink                                 [A] Unlink listening UNIX socket before binding to it
    -V, --version                                Prints version information
    -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
        --websocket-ignore-zeromsg
            [A] Silently drop incoming zero-length WebSocket messages. They may cause connection close due to usage of
            zero-len message as EOF flag inside Websocat.
    -t, --text                                   Send message to WebSockets as text messages
        --base64
            Encode incoming binary WebSocket messages in one-line Base64 If `--binary-prefix` (see `--help=full`) is
            set, outgoing WebSocket messages that start with the prefix are decoded from base64 prior to sending.
        --base64-text
            [A] Encode incoming text WebSocket messages in one-line Base64. I don't know whether it can be ever useful,
            but it's for symmetry with `--base64`.

OPTIONS:
        --socks5 <auto_socks5>
            Use specified address:port as a SOCKS5 proxy. Note that proxy authentication is not supported yet. Example:
            --socks5 127.0.0.1:9050
        --autoreconnect-delay-millis <autoreconnect_delay_millis>
            [A] Delay before reconnect attempt for `autoreconnect:` overlay. [default: 20]

        --basic-auth <basic_auth>
            Add `Authorization: Basic` HTTP request header with this base64-encoded parameter

        --queue-len <broadcast_queue_len>
            [A] Number of pending queued messages for broadcast reuser [default: 16]

    -B, --buffer-size <buffer_size>                                  Maximum message size, in bytes [default: 65536]
        --byte-to-exit-on <byte_to_exit_on>
            [A] Override the byte which byte_to_exit_on: overlay looks for [default: 28]

        --client-pkcs12-der <client_pkcs12_der>                      [A] Client identity TLS certificate
        --client-pkcs12-passwd <client_pkcs12_passwd>
            [A] Password for --client-pkcs12-der pkcs12 archive. Required on Mac.

        --close-reason <close_reason>
            Close connection with a reason message. This option only takes effect if --close-status-code option is
            provided as well.
        --close-status-code <close_status_code>                      Close connection with a status code.
        --crypto-key <crypto_key>
            [A] Specify encryption/decryption key for `crypto:` specifier. Requires `base64:`, `file:` or `pwd:` prefix.

    -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. Note that single -H may eat multiple further
            arguments, leading to confusing errors. Specify headers at the end or with equal sign like -H='X: y'.
        --server-header <custom_reply_headers>...
            Add custom HTTP header to websocket upgrade reply. Separate header name and value with a colon and
            optionally a single space. Can be used multiple times. Note that single -H may eat multiple further
            arguments, leading to confusing errors.
        --exec-args <exec_args>...
            [A] Arguments for the `exec:` specifier. Must be the last option, everything after it gets into the exec
            args list.
        --header-to-env <headers_to_env>...
            Forward specified incoming request header to H_* environment variable for `exec:`-like specifiers.

    -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.
        --inhibit-pongs <inhibit_pongs>
            [A] Stop replying to incoming WebSocket pings after specified number of replies

        --just-generate-accept <just_generate_accept>
            [A] Just a Sec-WebSocket-Accept value based on supplied Sec-WebSocket-Key value without running main
            Websocat
        --lengthprefixed-nbytes <lengthprefixed_header_bytes>
            [A] Use this number of length header bytes for `lengthprefixed:` overlay. [default: 4]

        --max-messages <max_messages>
            Maximum number of messages to copy in one direction.

        --max-messages-rev <max_messages_rev>
            Maximum number of messages to copy in the other direction.

        --conncap <max_parallel_conns>
            Maximum number of simultaneous connections for listening mode

        --max-sent-pings <max_sent_pings>
            [A] Stop sending pings after this number of sent pings

        --max-ws-frame-length <max_ws_frame_length>
            [A] Maximum size of incoming WebSocket frames, to prevent memory overflow [default: 104857600]

        --max-ws-message-length <max_ws_message_length>
            [A] Maximum size of incoming WebSocket messages (sans of one data frame), to prevent memory overflow
            [default: 209715200]
        --origin <origin>                                            Add Origin HTTP header to websocket client request
        --pkcs12-der <pkcs12_der>
            Pkcs12 archive needed to accept SSL connections, certificate and key.
            A command to output it: openssl pkcs12 -export -out output.pkcs12 -inkey key.pem -in cert.pem
            Use with -s (--server-mode) option or with manually specified TLS overlays.
            See moreexamples.md for more info.
        --pkcs12-passwd <pkcs12_passwd>
            Password for --pkcs12-der pkcs12 archive. Required on Mac.

    -p, --preamble <preamble>...
            Prepend copied data with a specified string. Can be specified multiple times.

    -P, --preamble-reverse <preamble_reverse>...
            Prepend copied data with a specified string (reverse direction). Can be specified multiple times.

        --prometheus <prometheus>
            Expose Prometheus metrics on specified IP address and port in addition to running usual Websocat session

        --request-header <request_headers>...
            [A] Specify HTTP request headers for `http-request:` specifier.

    -X, --request-method <request_method>                            [A] Method to use for `http-request:` specifier
        --request-uri <request_uri>                                  [A] URI to use for `http-request:` specifier
        --restrict-uri <restrict_uri>
            When serving a websocket, only accept the given URI, like `/ws`
            This liberates other URIs for things like serving static files or proxying.
    -F, --static-file <serve_static_files>...
            Serve a named static file for non-websocket connections.
            Argument syntax: <URI>:<Content-Type>:<file-path>
            Argument example: /index.html:text/html:index.html
            Directories are not and will not be supported for security reasons.
            Can be specified multiple times. Recommended to specify them at the end or with equal sign like `-F=...`,
            otherwise this option may eat positional arguments
        --socks5-bind-script <socks5_bind_script>
            [A] Execute specified script in `socks5-bind:` mode when remote port number becomes known.

        --socks5-destination <socks_destination>
            [A] Examples: 1.2.3.4:5678  2600:::80  hostname:5678

        --tls-domain <tls_domain>
            [A] Specify domain for SNI or certificate verification when using tls-connect: overlay

        --udp-multicast <udp_join_multicast_addr>...
            [A] Issue IP[V6]_ADD_MEMBERSHIP for specified multicast address. Can be specified multiple times.

        --udp-multicast-iface-v4 <udp_join_multicast_iface_v4>...
            [A] IPv4 address of multicast network interface. Has to be either not specified or specified the same number
            of times as multicast IPv4 addresses. Order matters.
        --udp-multicast-iface-v6 <udp_join_multicast_iface_v6>...
            [A] Index of network interface for IPv6 multicast. Has to be either not specified or specified the same
            number of times as multicast IPv6 addresses. Order matters.
        --udp-ttl <udp_ttl>                                          [A] Set IP_TTL, also IP_MULTICAST_TTL if applicable
        --protocol <websocket_protocol>
            Specify this Sec-WebSocket-Protocol: header when connecting

        --server-protocol <websocket_reply_protocol>
            Force this Sec-WebSocket-Protocol: header when accepting a connection

        --websocket-version <websocket_version>                      Override the Sec-WebSocket-Version value
        --binary-prefix <ws_binary_prefix>
            [A] Prepend specified text to each received WebSocket binary message. Also strip this prefix from outgoing
            messages, explicitly marking them as binary even if `--text` is specified
        --ws-c-uri <ws_c_uri>
            [A] URI to use for ws-c: overlay [default: ws://0.0.0.0/]

        --ping-interval <ws_ping_interval>                           Send WebSocket pings each this number of seconds
        --ping-timeout <ws_ping_timeout>
            Drop WebSocket connection if Pong message not received for this number of seconds

        --text-prefix <ws_text_prefix>
            [A] Prepend specified text to each received WebSocket text message. Also strip this prefix from outgoing
            messages, explicitly marking them as text even if `--binary` is specified

ARGS:
    <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://ws.vi-server.org/mirror/
    
  WebSocket server
    websocat -s 8080
    
  WebSocket-to-TCP proxy:
    websocat --binary ws-l:127.0.0.1:8080 tcp:127.0.0.1:5678
    

Full 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.
	inetd-ws:       	WebSocket inetd server. [A]
	l-ws-unix:      	WebSocket UNIX socket-based server. [A]
	l-ws-abstract:  	WebSocket abstract-namespaced UNIX socket server. [A]
	ws-lowlevel-client:	[A] Low-level HTTP-independent WebSocket client connection without associated HTTP upgrade.
	ws-lowlevel-server:	[A] Low-level HTTP-independent WebSocket server connection without associated HTTP upgrade.
	wss-listen:     	Listen for secure WebSocket connections on a TCP port
	http:           	[A] Issue HTTP request, receive a 1xx or 2xx reply, then pass
	asyncstdio:     	[A] Set stdin and stdout to nonblocking mode, then use it as a communication counterpart. UNIX-only.
	inetd:          	Like `asyncstdio:`, but intended for inetd(8) usage. [A]
	tcp:            	Connect to specified TCP host and port. Argument is a socket address.
	tcp-listen:     	Listen TCP port on specified address.
	ssl-listen:     	Listen for SSL connections on a TCP port
	sh-c:           	Start specified command line using `sh -c` (even on Windows)
	cmd:            	Start specified command line using `sh -c` or `cmd /C` (depending on platform)
	exec:           	Execute a program directly (without a subshell), providing array of arguments on Unix [A]
	readfile:       	Synchronously read a file. Argument 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
	open-async:     	Open file for read and write and use it like a socket. [A]
	open-fd:        	Use specified file descriptor like a socket. [A]
	threadedstdio:  	[A] Stdin/stdout, spawning a thread (threaded version).
	-               	Read input from console, print to console. Uses threaded implementation even on UNIX unless requested by `--async-stdio` CLI option.
	unix:           	Connect to UNIX socket. Argument is filesystem path. [A]
	unix-listen:    	Listen for connections on a specified UNIX socket [A]
	unix-dgram:     	Send packets to one path, receive from the other. [A]
	abstract:       	Connect to UNIX abstract-namespaced socket. Argument is some string used as address. [A]
	abstract-listen:	Listen for connections on a specified abstract UNIX socket [A]
	abstract-dgram: 	Send packets to one address, receive from the other. [A]
	mirror:         	Simply copy output to input. No arguments needed.
	literalreply:   	Reply with a specified string for each input packet.
	clogged:        	Do nothing. Don't read or write any bytes. Keep connections in "hung" state. [A]
	literal:        	Output a string, discard input.
	assert:         	Check the input.  [A]
	assert2:        	Check the input. [A]
	seqpacket:      	Connect to AF_UNIX SOCK_SEQPACKET socket. Argument is a filesystem path. [A]
	seqpacket-listen:	Listen for connections on a specified AF_UNIX SOCK_SEQPACKET socket [A]
	random:         	Generate random bytes when being read from, discard written bytes.
Full list of overlays:
	ws-upgrade:     	WebSocket upgrader / raw server. Specify your own protocol instead of usual TCP. [A]
	http-request:   	[A] Issue HTTP request, receive a 1xx or 2xx reply, then pass
	http-post-sse:  	[A] Accept HTTP/1 request. Then, if it is GET,
	ssl-connect:    	Overlay to add TLS encryption atop of existing connection [A]
	ssl-accept:     	Accept an TLS connection using arbitrary backing stream. [A]
	reuse-raw:      	Reuse subspecifier for serving multiple clients: unpredictable mode. [A]
	broadcast:      	Reuse this connection for serving multiple clients, sending replies to all clients.
	autoreconnect:  	Re-establish underlying connection on any error or EOF
	ws-c:           	Low-level WebSocket connector. Argument is a some another address. [A]
	msg2line:       	Line filter: Turns messages from packet stream into lines of byte stream. [A]
	line2msg:       	Line filter: turn lines from byte stream into messages as delimited by '\\n' or '\\0' [A]
	lengthprefixed: 	Turn stream of bytes to/from data packets with length-prefixed framing.  [A]
	foreachmsg:     	Execute something for each incoming message.
	log:            	Log each buffer as it pass though the underlying connector.
	jsonrpc:        	[A] Turns messages like `abc 1,2` into `{"jsonrpc":"2.0","id":412, "method":"abc", "params":[1,2]}`.
	timestamp:      	[A] Prepend timestamp to each incoming message.
	socks5-connect: 	SOCKS5 proxy client (raw) [A]
	socks5-bind:    	SOCKS5 proxy client (raw, bind command) [A]
	crypto:         	[A] Encrypts written messages and decrypts (and verifies) read messages with a static key, using ChaCha20-Poly1305 algorithm.
	prometheus:     	[A] Account connections, messages, bytes and other data and expose Prometheus metrics on a separate port.
	exit_on_specific_byte:	[A] Turn specific byte into a EOF, allowing user to escape interactive Websocat session
	waitfordata:    	Wait for some data to pending being written before starting connecting. [A]

Some notes

  • IPv6 is supported, surround your IP in square brackets or use it as is, depending on context.
  • Web socket usage is not obligatory, you can use any specs on both sides.
  • Typically one line in binary stream correspond to one WebSocket text message. This is adjustable with options.

Limitations

  • It is not convenient when text and binary WebSocket messages are mixed. This affects mirror: specifier, making it a bit different from ws://echo.websocket.org. There are --binary-prefix, --text-prefix and --base64 options to handle mixture of binary and text.
  • Current version of Websocat don't receive notification about closed sockets. This makes serving without -E or -u options or in backpressure scenarios prone to socket leak.
  • Readline is not integrated. Users are advices to wrap websocat using rlwrap tool for more convenient CLI.
  • Build process of current version of Websocat is not properly automated and is fragile.

See also

websocat's People

Contributors

0mp avatar 0xflotus avatar akostadinov avatar delapouite avatar dependabot[bot] avatar dreamacro avatar herbygillot avatar josegonzalez avatar kianmeng avatar therealprof avatar tibkiss avatar tim77 avatar vi avatar yonas avatar zbinlin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

websocat's Issues

How to connect and send request in command line ?

Hi.

Thank for this tool !

I want to launch in command line websocat with a request. I try this :

websocat ws://url:port | echo 'request in JSON'

But not work.

I want to record the result in a file. How i do ?

Sorry for my bad english ...

Thank for your reply and your help.

wss has changed

wss shows this message now

$ websocat.exe -t wss://echo.websocket.org
websocat: Unknown address or overlay type of `wss://echo.websocket.org`

it was good with the old version
thank you

slab: error: the optimizations s or z are only accepted on the nightly compiler

 cargo build --release --features=ssl
    Updating registry `https://github.com/rust-lang/crates.io-index`
warning: spurious network error (2 tries remaining): [12/-2] [18] Transferred a partial file (transfer closed with outstanding read data remaining)
warning: spurious network error (1 tries remaining): [12/-2] [56] Failure when receiving data from the peer (Received HTTP code 503 from proxy after CONNECT)
 Downloading readwrite v0.1.1
 Downloading structopt v0.2.14
 Downloading slab_typesafe v0.1.3
 Downloading tokio-reactor v0.1.9
 Downloading websocket v0.22.3
 Downloading tokio-udp v0.1.3
 Downloading tokio-process v0.2.3
 Downloading tokio-tls v0.2.1
 Downloading tokio-tcp v0.1.3
 Downloading tokio-current-thread v0.1.5
 Downloading futures v0.1.25
 Downloading native-tls v0.2.2
 Downloading hyper v0.10.15
 Downloading tokio-io v0.1.12
 Downloading tokio-codec v0.1.1
 Downloading derivative v1.0.2
 Downloading smart-default v0.3.0
 Downloading env_logger v0.6.0
 Downloading log v0.4.6
 Downloading tokio v0.1.16
 Downloading url v1.7.2
 Downloading tokio-stdin-stdout v0.1.5
 Downloading tk-listen v0.2.1
 Downloading bytes v0.4.11
 Downloading cfg-if v0.1.7
 Downloading byteorder v1.3.1
 Downloading iovec v0.1.2
 Downloading clap v2.32.0
 Downloading structopt-derive v0.2.14
 Downloading textwrap v0.10.0
 Downloading bitflags v1.0.4
 Downloading unicode-width v0.1.5
 Downloading heck v0.3.1
 Downloading proc-macro2 v0.4.27
 Downloading quote v0.6.11
 Downloading syn v0.15.27
 Downloading unicode-segmentation v1.2.1
 Downloading unicode-xid v0.1.0
 Downloading slab v0.4.2
 Downloading num_cpus v1.10.0
 Downloading mio v0.6.16
 Downloading crossbeam-utils v0.6.5
 Downloading lazy_static v1.3.0
 Downloading tokio-sync v0.1.3
 Downloading tokio-executor v0.1.6
 Downloading parking_lot v0.7.1
 Downloading libc v0.2.50
 Downloading lazycell v1.2.1
 Downloading net2 v0.2.33
 Downloading fnv v1.0.6
 Downloading parking_lot_core v0.4.0
 Downloading lock_api v0.1.5
 Downloading smallvec v0.6.9
 Downloading rand v0.6.5
 Downloading rand_core v0.4.0
 Downloading rand_isaac v0.1.1
 Downloading rand_jitter v0.1.3
 Downloading rand_chacha v0.1.1
 Downloading rand_os v0.1.3
 Downloading rand_hc v0.1.0
 Downloading rand_xorshift v0.1.1
 Downloading rand_pcg v0.1.2
 Downloading rand_core v0.3.1
 Downloading autocfg v0.1.2
 Downloading rustc_version v0.2.3
 Downloading semver v0.9.0
 Downloading semver-parser v0.7.0
 Downloading scopeguard v0.3.3
 Downloading owning_ref v0.4.0
 Downloading stable_deref_trait v1.1.1
 Downloading sha1 v0.6.0
 Downloading base64 v0.10.1
 Downloading unicase v1.4.2
 Downloading matches v0.1.8
 Downloading percent-encoding v1.0.1
 Downloading idna v0.1.5
 Downloading unicode-normalization v0.1.8
 Downloading unicode-bidi v0.3.4
 Downloading tokio-threadpool v0.1.12
 Downloading tokio-fs v0.1.6
 Downloading tokio-timer v0.2.10
 Downloading crossbeam-queue v0.1.2
 Downloading crossbeam-deque v0.7.1
 Downloading crossbeam-epoch v0.7.1
 Downloading memoffset v0.2.1
 Downloading arrayvec v0.4.10
 Downloading nodrop v0.1.13
 Downloading log v0.3.9
 Downloading httparse v1.3.3
 Downloading typeable v0.1.2
 Downloading time v0.1.42
 Downloading language-tags v0.2.2
 Downloading mime v0.2.6
 Downloading traitobject v0.1.0
 Downloading base64 v0.9.3
 Downloading version_check v0.1.5
 Downloading safemem v0.3.0
 Downloading tokio-uds v0.2.5
 Downloading tokio-file-unix v0.5.1
 Downloading tokio-signal v0.2.7
 Downloading mio-uds v0.6.7
 Downloading openssl-probe v0.1.2
 Downloading openssl-sys v0.9.42
 Downloading openssl v0.10.19
 Downloading pkg-config v0.3.14
 Downloading cc v1.0.30
 Downloading foreign-types v0.3.2
 Downloading foreign-types-shared v0.1.1
 Downloading signal-hook v0.1.8
 Downloading arc-swap v0.3.7
   Compiling nodrop v0.1.13
   Compiling byteorder v1.3.1
   Compiling traitobject v0.1.0
   Compiling lazycell v1.2.1
   Compiling matches v0.1.8
   Compiling safemem v0.3.0
   Compiling openssl v0.10.19
   Compiling lazy_static v1.3.0
   Compiling pkg-config v0.3.14
   Compiling rand_core v0.4.0
   Compiling unicode-xid v0.1.0
   Compiling fnv v1.0.6
   Compiling autocfg v0.1.2
   Compiling smallvec v0.6.9
   Compiling openssl-probe v0.1.2
   Compiling language-tags v0.2.2
   Compiling stable_deref_trait v1.1.1
   Compiling sha1 v0.6.0
   Compiling unicode-width v0.1.5
   Compiling native-tls v0.2.2
   Compiling foreign-types-shared v0.1.1
   Compiling version_check v0.1.5
   Compiling scopeguard v0.3.3
   Compiling arc-swap v0.3.7
   Compiling futures v0.1.25
   Compiling cfg-if v0.1.7
   Compiling libc v0.2.50
   Compiling arrayvec v0.4.10
   Compiling httparse v1.3.3
   Compiling proc-macro2 v0.4.27
   Compiling unicode-segmentation v1.2.1
   Compiling cc v1.0.30
   Compiling memoffset v0.2.1
   Compiling bitflags v1.0.4
   Compiling typeable v0.1.2
   Compiling percent-encoding v1.0.1
   Compiling semver-parser v0.7.0
   Compiling slab v0.4.2
error: the optimizations s or z are only accepted on the nightly compiler

error: the optimizations s or z are only accepted on the nightly compiler

error: the optimizations s or z are only accepted on the nightly compiler

error: Could not compile `byteorder`.
warning: build failed, waiting for other jobs to finish...
error:error : the optimizations s or z are only accepted on the nightly compilerCould not compile `traitobject`.
warning: build failed, waiting for other jobs to finish...


error: the optimizations s or z are only accepted on the nightly compiler

error: the optimizations s or z are only accepted on the nightly compiler

error: Could not compile `openssl`.
warning: build failed, waiting for other jobs to finish...
error: the optimizations s or z are only accepted on the nightly compiler

error: Could not compile `lazycell`.
warning: build failed, waiting for other jobs to finish...
error: Could not compile `nodrop`.
warning: build failed, waiting for other jobs to finish...
error: Could not compile `safemem`.
error: the optimizations s or z are only accepted on the nightly compiler
warning: build failed, waiting for other jobs to finish...
error: Could not compile `lazy_static`.
warning: build failed, waiting for other jobs to finish...

error: Could not compile `matches`.
warning: build failed, waiting for other jobs to finish...
error: the optimizations s or z are only accepted on the nightly compiler

error: Could not compile `rand_core`.
warning: build failed, waiting for other jobs to finish...
error: the optimizations s or z are only accepted on the nightly compiler

error: the optimizations s or z are only accepted on the nightly compiler

error: the optimizations s or z are only accepted on the nightly compiler

error: Could not compile `fnv`.
warning: build failed, waiting for other jobs to finish...
error: Could not compile `pkg-config`.
warning: build failed, waiting for other jobs to finish...
error: the optimizations s or z are only accepted on the nightly compiler

error: Could not compile `smallvec`.
warning: build failed, waiting for other jobs to finish...
error: Could not compile `cc`.
warning: build failed, waiting for other jobs to finish...
error: the optimizations s or z are only accepted on the nightly compiler

error: Could not compile `autocfg`.
warning: build failed, waiting for other jobs to finish...
error: the optimizations s or z are only accepted on the nightly compiler

error: the optimizations s or z are only accepted on the nightly compiler

error: the optimizations s or z are only accepted on the nightly compiler

error: Could not compile `stable_deref_trait`.
warning: build failed, waiting for other jobs to finish...
error: Could not compile `scopeguard`.
warning: build failed, waiting for other jobs to finish...
error: Could not compile `arc-swap`.
warning: build failed, waiting for other jobs to finish...
error: the optimizations s or z are only accepted on the nightly compiler

error: the optimizations s or z are only accepted on the nightly compiler

error: Could not compile `unicode-width`.
warning: build failed, waiting for other jobs to finish...
error: the optimizations s or z are only accepted on the nightly compiler

error: Could not compile `sha1`.
warning: build failed, waiting for other jobs to finish...
error: Could not compile `openssl-probe`.
warning: build failed, waiting for other jobs to finish...
error: the optimizations s or z are only accepted on the nightly compiler

error: the optimizations s or z are only accepted on the nightly compiler

error: the optimizations s or z are only accepted on the nightly compiler

error: Could not compile `percent-encoding`.
warning: build failed, waiting for other jobs to finish...
error: Could not compile `memoffset`.
warning: build failed, waiting for other jobs to finish...
error: Could not compile `httparse`.
warning: build failed, waiting for other jobs to finish...
errorerror: the optimizations s or z are only accepted on the nightly compiler: the optimizations s or z are only accepted on the nightly compiler



error: Could not compile `unicode-xid`.
warning: build failed, waiting for other jobs to finish...
error: Could not compile `foreign-types-shared`.
warning: build failed, waiting for other jobs to finish...
error: the optimizations s or z are only accepted on the nightly compiler

error: Could not compile `native-tls`.
warning: build failed, waiting for other jobs to finish...
error: the optimizations s or z are only accepted on the nightly compiler

error: Could not compile `cfg-if`.
warning: build failed, waiting for other jobs to finish...
error: the optimizations s or z are only accepted on the nightly compiler

error: Could not compile `language-tags`.
warning: build failed, waiting for other jobs to finish...
error: the optimizations s or z are only accepted on the nightly compiler

error: Could not compile `typeable`.
warning: build failed, waiting for other jobs to finish...
error: the optimizations s or z are only accepted on the nightly compiler

error: the optimizations s or z are only accepted on the nightly compiler

error: the optimizations s or z are only accepted on the nightly compiler

error: the optimizations s or z are only accepted on the nightly compiler

error: Could not compile `libc`.
warning: build failed, waiting for other jobs to finish...
error: Could not compile `version_check`.
warning: build failed, waiting for other jobs to finish...
error: Could not compile `slab`.
warning: build failed, waiting for other jobs to finish...
error: the optimizations s or z are only accepted on the nightly compiler

error: Could not compile `arrayvec`.
warning: build failed, waiting for other jobs to finish...
error: the optimizations s or z are only accepted on the nightly compiler

error: Could not compile `futures`.
warning: build failed, waiting for other jobs to finish...
error: Could not compile `bitflags`.
warning: build failed, waiting for other jobs to finish...
error: the optimizations s or z are only accepted on the nightly compiler

error: the optimizations s or z are only accepted on the nightly compiler

error: Could not compile `semver-parser`.
warning: build failed, waiting for other jobs to finish...
error: Could not compile `proc-macro2`.
warning: build failed, waiting for other jobs to finish...
error: the optimizations s or z are only accepted on the nightly compiler

error: Could not compile `unicode-segmentation`.

To learn more, run the command again with --verbose.

--line option need a better description

in an attempt to understand what --line do, my conclusion was that:
--linemode-retain-newlines only tells to --line don't remove the new lines that you remove secretly, because --line is removing every \n that it found.

the description in the help doesn't tell you it will remove \n. --line short description should contain i think this : \n will be removed and if you want to preserve them use --linemode-retain-newlines.

Dependency is not satisfiable: libssl1.1

When installing on Ubuntu 16.04

$ gdebi websocat_1.2.0_amd64.deb 
Reading package lists... Done
Building dependency tree        
Reading state information... Done
Reading state information... Done
This package is uninstallable
Dependency is not satisfiable: libssl1.1

TODO list

For publishing a crate:

  • Stdin to websocket client
  • Abstractions for boxed peer, peer constructor, peer stream
  • TCP connector and listener
  • Websocket server (no ssl)
  • Generic websocket server and client (custom connectors, not just TCP)
  • Replying to WebSocket pings
  • Intermediate structure between command-line strings and actual peers
  • Normal command line interface with a help message and options
  • --text option
  • exec: specifier
  • sh-c: specifier
  • Unidirectional option
  • UNIX and abstract listener and connector

For considering a non-alpha release:

  • Make it singlethreaded and/or provide explicit --threaded option.
  • Correct handling for EOF / socket shutdown
  • More thorough testing
  • Line mode for websockets
  • More useful logging (connection log), -v and --quiet options
  • Option to execute a program on each message, not on each connection.
  • unix seqpacket
  • More lints
  • Delays between reconnects for autoreconnect:
  • De-hardcode buffer size

Further ideas:

  • Non-websocket content redirector
  • SSL listener and connector
  • SCTP
  • Pure Rust SSL support
  • Environment variables like URL for exec:
  • Special JSON powers?
  • Specifying cookies and other HTTP headers.
  • Propagation of "can't accept writes anymore" status.

Websocat in servermode eating a CPU core after closing TCP socket

I noticed that with my misbehaving client if I just close the TCP socket on the client side, the loop in block_on will run at maximum speed just spinning:

    frame #36: 0x0000000100028241 websocat`tokio::runtime::current_thread::runtime::Runtime::block_on::h5787e30364afd47d(self=0x00007fff5fbfd788, f=<unavailable>) + 81 at runtime.rs:189
    frame #37: 0x0000000100006f69 websocat`websocat::run::he5b002ccc4cdf93a + 11529 at main.rs:672
    frame #38: 0x0000000100009130 websocat`websocat::main::h64c0053338159ebd + 16 at main.rs:678

Not sure where exactly the bug is but I would expect websocat to handle such a situation.

version v1.0.0-alpha have problems when parsing the args

Hi,
First I want to thank you for this gem. thank you very much.

The new version v1.0.0-alpha can't parse the args well, the old version 0.4 works well!.
I m using cygwin in windows 7.

using this exemple : https://stackoverflow.com/questions/48912184/wscat-commands-from-script-how-to-pass/48914019#48914019

#!/usr/bin/env bash

runscript() {
  commands=( "first command" "second command" "third command" )

  for command in "${commands[@]}"; do
    echo "Writing command to server" >&2
    echo "$command"
    echo "Reading response from server (assuming exactly one line)" >&2
    read -r line
    echo "Received response: $line" >&2
  done

  # kill websocat, even if the websocket doesn't get closed
  kill "$PPID"
}

export -f runscript

the new version gaves this error

$ ./websocat_nossl_1.0_i686-pc-windows-gnu.exe ws://echo.websocket.org sh-c:'exec bash -c runscript'
'exec' is not recognized as an internal or external command,
operable program or batch file.

using the old version 0.4 everything works fine:

$ ./websocat_nossl_0.4_i686-pc-windows-gnu.exe ws://echo.websocket.org sh-c:'exec bash -c runscript'
INFO:websocat: Connecting to ws://echo.websocket.org/
INFO:websocat: Validating response...
INFO:websocat: Successfully connected
Writing command to server
Reading response from server (assuming exactly one line)
Received response: first command
Writing command to server
Reading response from server (assuming exactly one line)
Received response: second command
Writing command to server
Reading response from server (assuming exactly one line)
Received response: third command
environment: line 9: kill: (1) - No such process
The pipe is being closed. (os error 232)

the version 0.5 too have problems, but seems a different error:

$ ./websocat-0.5.1--windows.exe ws://echo.websocket.org sh-c:'exec bash -c runscript'
websocat: WebSocketError: WebSocket URL failure

thank you.

how to add headers?

Hi,
Is it possible to add headers? the documentation doesn't talk about this , and the source code doesn't show a possibility to add it. my websocket server need specific headers to be added like Origin: http://127.0.0.1:9222
thank you

MAC verification failed during PKCS12 import

Running the latest version from Homebrew (websocat 1.2.0, and socat 1.7.3.2)

In one window, running this command (using test.pkcs12 from the git repo):

$ websocat --pkcs12-der=test.pkcs12 -s 1234
Listening on wss://127.0.0.1:1234/

In another window, running the command:

websocat -t --ws-c-uri=wss://127.0.0.1:1234/ - ws-c:cmd:'socat - ssl:127.0.0.1:1234,verify=0'

Once the connection is established, the "server" window displays the error:

websocat: MAC verification failed during PKCS12 import (wrong password?)

And the "client" window displays the error:

2019/03/01 07:15:13 socat[44652] E SSL_connect(): socket closed by peer
websocat: WebSocketError: WebSocket protocol error
websocat: error running

User friendliness TODO list

  • single arg mode
  • Text and line mode by default Overhaul line and text mode options.
  • better description of options
  • Proper manual, move reference away from README.
  • Better repository description
  • Introductory examples in README
  • More pre-built versions with SSL support?
  • Github Pages site.
  • Extend examples with sample output and connection command lines
  • Manpage in deb.
  • Rename "specifier" to "address".
  • Warnings visible by default.

Authentication

Great tool, but I cannot find a way to do authenticated connects with basic auth. Could you please tell me how to archive this or add this option?

I am working in a business environment where no server allows anonymous connections. I am quite surprised nobody missed this before.

Thanks!

Please add support for specifying a proxy server

I wanted to use websocat to help me file a bug report in OWASP ZAP, but I can't do that unless I can point it at the ZAP proxy endpoint. This would be useful for other things as well, of course.

Build failure - smart-default / quote

Fully admit I don't know a lot of Rust so not sure what is wrong. From what I gather quote fails to compile? 45523d8 tries to bump the minimum rust version but I didn't receive any such error.

   Compiling websocket v0.22.0
error[E0432]: unresolved import `quote::quote`
  --> /dev/shm/.cargo/registry/src/github.com-1ecc6299db9ec823/smart-default-0.3.0/src/lib.rs:15:13
   |
15 | use quote::{quote, ToTokens};
   |             ^^^^^ no `quote` in the root

error: cannot find macro `parse_macro_input!` in this scope
  --> /dev/shm/.cargo/registry/src/github.com-1ecc6299db9ec823/smart-default-0.3.0/src/lib.rs:64:17
   |
64 |     let input = parse_macro_input!(input as DeriveInput);
   |                 ^^^^^^^^^^^^^^^^^

error: cannot find macro `quote!` in this scope
  --> /dev/shm/.cargo/registry/src/github.com-1ecc6299db9ec823/smart-default-0.3.0/src/lib.rs:82:14
   |
82 |             (quote! {
   |              ^^^^^

error: cannot find macro `quote!` in this scope
   --> /dev/shm/.cargo/registry/src/github.com-1ecc6299db9ec823/smart-default-0.3.0/src/lib.rs:100:14
    |
100 |             (quote! {
    |              ^^^^^

error: cannot find macro `quote!` in this scope
   --> /dev/shm/.cargo/registry/src/github.com-1ecc6299db9ec823/smart-default-0.3.0/src/lib.rs:108:8
    |
108 |     Ok(quote! {
    |        ^^^^^

error: cannot find macro `quote!` in this scope
   --> /dev/shm/.cargo/registry/src/github.com-1ecc6299db9ec823/smart-default-0.3.0/src/lib.rs:182:13
    |
182 |         Ok((quote! {
    |             ^^^^^

error: cannot find macro `quote!` in this scope
   --> /dev/shm/.cargo/registry/src/github.com-1ecc6299db9ec823/smart-default-0.3.0/src/lib.rs:168:31
    |
168 |         &syn::Fields::Unit => quote!{},
    |                               ^^^^^

error: cannot find macro `quote!` in this scope
   --> /dev/shm/.cargo/registry/src/github.com-1ecc6299db9ec823/smart-default-0.3.0/src/lib.rs:132:24
    |
132 |                     Ok(quote! { #field_name : #default_value })
    |                        ^^^^^

error: cannot find macro `quote!` in this scope
   --> /dev/shm/.cargo/registry/src/github.com-1ecc6299db9ec823/smart-default-0.3.0/src/lib.rs:134:17
    |
134 |                 quote!{
    |                 ^^^^^

error: cannot find macro `quote!` in this scope
   --> /dev/shm/.cargo/registry/src/github.com-1ecc6299db9ec823/smart-default-0.3.0/src/lib.rs:155:17
    |
155 |                 quote! {
    |                 ^^^^^

error: aborting due to 10 previous errors

For more information about this error, try `rustc --explain E0432`.
error: Could not compile `smart-default`.
warning: build failed, waiting for other jobs to finish...
error: build failed

Receiver flow control

I'm trying to transfer potentially infinite stream from server to client (browser). When the client does not consume messages fast enough some get lost with the
[WARN websocat::broadcast_reuse_peer] A client's sink is NotReady for start_send
message in websocat stderr. I'd like the websocat in this situation to block until send buffer clears, is it possible? Since TCP already has flow control I'd prefer not to reproduce it on the application level, potentially ruining performance.

(Also, the warning is misleading, should be fatal error IMO since partial stream loss causes either protocol breakage or unintended operation.)

Skip SSL/TLS verification?

I was looking for something similar to curl -k option that lets you test a HTTPS endpoint even if you cannot verify the certificate. This is very useful for debug scenarios. Unfortunately I can't seem to find such an option if it exists.

strange behavior in "simple one-argument mode"

I created a websocket server with websocat

 websocat ws-l:127.0.0.1:8888 -

then I opened another websocat as client to connect to this server (using the simple one-argument mode)

printf 'A\nB\nC\n' | websocat ws://127.0.0.1:8888

the expected is : the server should show my messages.
the bug: websocat server will buffer the messages he receives (wireshark shows that the server is receiving the messages and responding correctly with [ACK] ).
if I send a \n to the server then he will print all the old messages that he received before.

two-arguments mode works as expected like this websocat ws://127.0.0.1:8888 -

REQUEST: Specify unexpected status code

When the server gives an error, the program indicates:

websocat: WebSocketError: Received unexpected status code

It would be nice if it would specify what the status code actually was, e.g.:

websocat: WebSocketError: Received unexpected status code (404)

websocat server doesn't reply with Sec-WebSocket-Protocol

As per RFC 6455, if the client includes a Sec-WebSocket-Protocol header, the server must pick one of the available protocols and send back a Sec-WebSocket-Protocol header with the selection made. If it does not send back a Sec-WebSocket-Protocol the client must assume the connection to have failed.

However, (in simple server mode) websocat neither sends back the header by itself nor does the --protocol switch seem to work for some reason.

To capture specific field data

When I use this tool create a websocket, it will keep connection get data continuously,
If I can just request a specific field data, when I get it then disconnect the connection?

for example, I just want to get this in the field {"data":{"count":{"number":}}}

fails on IEX TOPS

https://iextrading.com/developer/docs/

Their example works in node but not in websocat.

Just so you know.

    WebSockets example that shows a connection to the tops channel and a subscribtion to snap,fb,aig+ topics

// Import socket.io with a connection to a channel (i.e. tops)
const socket = require('socket.io-client')('https://ws-api.iextrading.com/1.0/tops')

// Listen to the channel's messages
socket.on('message', message => console.log(message))

// Connect to the channel
socket.on('connect', () => {

    // Subscribe to topics (i.e. appl,fb,aig+)
      socket.emit('subscribe', 'snap,fb,aig+')

        // Unsubscribe from topics (i.e. aig+)
          socket.emit('unsubscribe', 'aig+')
})

// Disconnect from the channel
socket.on('disconnect', () => console.log('Disconnected.'))

Multiple Incoming messages

Good work on this project!
I have one question though, does the client keeps the websocket channel open for new incoming messages?

I have a particular scenario where the for one 'outgoing' request, I have two 'incoming' responses from the server. I can see the first response, but not the second ( I see it via the browser). I suspect the channel is closed, but some clarification would be appreciated.

Requests

Hi,

Thank you for this amazing tool.

I'm unfortunately not familiar with Rust (only C, C++, C#, PHP, JS) so my only option is to make a request to you (instead of coding/submitting it).

There are two features that I'm missing:

  1. I'm trying to get the peer IP when using "exec:binary".
    Would it be possible when I use --exec-args to support a built-in variable (ie: $IP) which would contain the peer IP ?

  2. Using signal instead of closing stdin when using "exec:binary".
    Would it be possible when I use "exec:binary" and the websocket is closed to send SIGHUP (for example) to the binary instead of closing its stdin ?

Regards.

SUPPORT / REQUEST

Hi,

First thanks for this tool ! I use it in many context (client / serveur / windows / Linux) for tests or POC purpose.

Is there a way for a program run by websocat (--exec) to get HTTP headers (I wish to get cookies) ?
Websocket server display headers with -v -v option, but I can't found a way to get them in my bash script:

websocat -v -v -e --exit-on-eof --text l-ws:0.0.0.0:3009 exec:/WS_user.sh --exec-args websocket
[INFO websocat::lints] Auto-inserting the line mode
...
[INFO websocat::net_peer] Incoming TCP connection from Some(V4(172.17.0.1:43036))
[DEBUG websocat::sessionserve] Underlying connection established
[INFO websocat::sessionserve] Serving 1 ongoing connections
[INFO websocat::ws_server_peer] Incoming connection to websocket: /wsock
[DEBUG websocat::ws_server_peer] Incoming { version: Http11, subject: (Get, AbsolutePath("/wsock")), headers: Headers { Upgrade: websocket
, Connection: upgrade
, Host: wtb_admin:3009
, Cookie: AUTH_TOKEN=80d02638a3cec601e7fbe0cdf6ecc5f4ccb3cce5
, Sec-WebSocket-Version: 13
, Sec-WebSocket-Key: PhjBHwNbV5p4+1dg5agWjA==
, } }
[DEBUG websocat::ws_server_peer] Headers { }
[DEBUG websocat::ws_server_peer] Headers { Sec-WebSocket-Accept: m+ZXqcHuSXeSb3tre38wz+oW1pQ=
, Connection: Upgrade
, Upgrade: websocket
, }
[INFO websocat::ws_server_peer] Upgraded

From client

websocat -H "Cookie: AUTH_TOKEN=80d02638a3cec601e7fbe0cdf6ecc5f4ccb3cce5" -k wss://endpoint/wsock
CONNECT from 172.17.0.1:43036
WEBSOCAT_URI=/wsock
WEBSOCAT_CLIENT=172.17.0.1:43036
SHLVL=2

Script:

echo CONNECT from ${WEBSOCAT_CLIENT}
env

send to websocket

I'm sorry, my cat walked through the keyboard yesterday! Please close the issue! I'm really sorry!

advice on how to redirect udp multicast messages

I am attempting to redirect broadcast UDP messages to javascript webpage clients.

My current approach is as follows as follows:

  1. create a named pipe: mkisofs /tmp/pipe
  2. tail the pipe and forward to websocat: tail -f /tmp/pipe | websocat -t -s 10.0.0.1:1234
  3. run a socat command in an infinite loop to receive messages from my base service that publishes UDP broadcast messages and append them to the pipe like this: while true; do socat -t 0 UDP4-RECVFROM:30000,ip-add-membership=224.223.222.221:127.0.0.1,reuseaddr STDOUT >> /tmp/pipe; done

The issue I'm seeing in my java script webpage is that some messages seem to batch up and arrive in groups while others do not. Messages are JSON arriving once every 4-8 seconds.

Is there a more straight forward approach I should be using to forward the UDP messages? Any ideas on messages seeming to batch?

thanks!

WebSocket Ping doesn't get response

I'm sending a WebSocket Ping to websocat running as server after establishing a connection but I don't receive a Pong:

Here's the text summary from wireshark:

9	10.008700	127.0.0.1	127.0.0.1	WebSocket	58	8090	WebSocket Ping [FIN] 

And this is the packet:

0000   02 00 00 00 45 00 00 36 97 21 40 00 40 06 00 00   ....E..6.!@.@...
0010   7f 00 00 01 7f 00 00 01 d1 f0 1f 9a df 6f 22 79   .............o"y
0020   f1 0b 47 f3 80 18 31 d3 fe 2a 00 00 01 01 08 0a   ..G...1..*......
0030   34 f1 f0 2d 34 f1 c9 3c 89 00                     4..-4..<..

Missing test coverage

  • read debt from web sockets
  • web socket ping/pong
  • text mode
  • ws-c
  • ws custom headers, origin, protocol, ws version
  • multiple overlays
  • unix dgram
  • stdio threaded peer
  • stdio peer
  • some_checks in specparse
  • unidirectional and exit-of-eof modes
  • serve multiple times
  • overlay without serving multiple times
  • autoreconnect
  • read debt handling: too long, too large
  • process peer
  • reuse peer primitive
  • reuse peer broadcast
  • UDP
  • mirror
  • lints
  • msg2line, line2msg
  • file peers

race condition when piping and closing

There is a race condition when piping to Websocat :
please see this two tests, using Websocat v1.0beta:

here I received the response, good :

$ printf  foo | websocat.exe - ws://127.0.0.1:9222/
{"error":{"code":-32700,"message":"Message must be a valid JSON"}}

here with the same test I did not receive the response :

$ printf  foo | websocat.exe - ws://127.0.0.1:9222/

if I repeat the test 10 times then only 3 or 4 times I receive the response...

fiddling with Wireshark I see that the close opcode flag is sent by Websocat sometimes before receiving the response of the server. if the server take time to answer then Websocat will close the connection before receiving the response.
is it possible to add a delay for the response, and if no response is received in that delay then close. or maybe there is a better solution?

NB:
using this solution I can close when needed and everything works fine because the race condition can never happen, but I wanted to know if it is possible to make it work with simple pipes.
Thank you

How to transfer text and binary data in one connection?

Thank you for your great tools. ^^

I want to use the Web SocketAPI. (via TCP)
ex) websocat tcp-l:127.0.0.1:4554 ws://123.456.789.012:8100/api/v1/fileupload

The API works with three commands:

  1. Deliver file information in json format. {"action":"create", "filename":"test.png"} -> text mode
  2. Deliver the actual contents of the file (test,png) -> binary mode
  3. end point of the file. {"action":"stop"} ->text mode

It determines the execution mode and allows only one to be used. (-t or -b)
Can I transfer binary data or text data while connected?
(I am using the Windows environment.)

Please add websocat to HomeBew

First I just want to say thanks for a very handy and great utility. It would be awesome if were available in HomeBrew. Thanks!

Running Arch, and something involving openssl failing? Here's the fix

Are you seeing this?

(lots of success)
.
.
.
error: failed to run custom build command for `openssl v0.9.24`
process didn't exit successfully: `/tmp/cargo-installeT1Fjp/release/build/openssl-52aea9a6aa0ce1e0/build-script-build` (exit code: 101)
--- stderr
thread 'main' panicked at 'Unable to detect OpenSSL version', /home/i336/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-0.9.24/build.rs:16:14
note: Run with `RUST_BACKTRACE=1` for a backtrace.

warning: build failed, waiting for other jobs to finish...
error: failed to compile `websocat v1.1.0`, intermediate artifacts can be found at `/tmp/cargo-installeT1Fjp`

Caused by:
  build failed

Do this, then rerun the cargo command:

export OPENSSL_LIB_DIR="/usr/lib/openssl-1.0"; export OPENSSL_INCLUDE_DIR="/usr/include/openssl-1.0"

"Why?!?"

sfackler/rust-openssl#994

Just saving someone a Google

Don't require second address in order to use flags

Hi, I want to use flags like -H to set headers, without specifying a second WebSocket address, as my application has exactly one address with no proxies.

Can we please provide for more CLI flexibility?

I/O failure when trying to talk to `localhost`

When I try to connect to localhost, I get this error, but when I use 127.0.0.1 instead, everything is fine. I guess websocat can't resolve names or something? curl can talk to the server running on localhost just fine.
Would be cool to have this fixed for ease of use. And thank you for the tool, it does seem to work quite well otherwise 👍

E.g.:

user@hostname $ websocat ws://localhost:8080/ws
websocat: WebSocketError: I/O failure
websocat: error running
user@hostname $ websocat ws://127.0.0.1:8080/ws
# no error
user@hostname $ curl localhost:8080/ws
# no error

one-argument mode and two-argument mode behave differently

using two-argument mode:
this will send my multi-line payload as 1 message and will retain \n . that is good

$  printf 'A\nB\n' | websocat - ws://echo.websocket.org/
A
B

now look please when using one-argument mode:
this will send 2 messages, but it considers that 1 line is 1 message! and it will remove the \n from every message sent.

$  printf 'A\nB\n' | websocat ws://echo.websocket.org/
A
B

why both examples don't have the same behavior? can one-argument mode have the same behavior like two-argument mode? or am I missing something?

how to specify server CA, client cert and client key when connecting to wss server?

In order to connect to a websocket service inside a pod in a minikube setup, I need to address the Kubernetes remote API which then demands a client certificate (~/.minikube/client.crt and ~/.minikube/client.key). I also have the server's CA ( ~/.minikube/ca.crt).

curl allows to use these certs with the --cert, --key, and --cacert options.

Does websocat also support specifying the client cert and the server CA when accessing a wss:// URL?

Using websocat as a websocket proxy

Suppose we would want to create a websocket proxy server using websocat.
For instance, client A needs to access ws://somedomain/somewhere. But the websocat to use would be on another computer, acting as a proxy.

What would be the easiest way to do that using websocat? I think it would necessitate another program that would accept the connection, read the target uri and then instantiate websocat with that target uri and a mirror:. Is there a simpler way?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.