9 个版本
0.0.40 | 2024 年 5 月 17 日 |
---|---|
0.0.7 | 2024 年 5 月 7 日 |
0.0.6 | 2024 年 1 月 27 日 |
0.0.5 | 2023 年 10 月 31 日 |
0.0.4 | 2023 年 8 月 31 日 |
#44 in WebSocket
73 次每月下载
450KB
11K SLoC
gnostr-cat
gnostr-cat 是 gnostr.org 命令行工具套件的一部分。
支持 docker 和 tor 的 nostr 中继脚本的 WebSocket 客户端命令行工具
示例
使用交互式输入
$ gnostr-cat wss://relay.damus.io <return>
["REQ", "RAND", {"kinds": [1], "limit": 8}] <return>
<ctrl-D>
使用 stdin(支持多行命令)
$ echo '["REQ", "RAND", {"kinds": [1], "limit": 8}]' |
gnostr-cat wss://relay.damus.io
$ cat commands.txt
["REQ", "RAND", {"kinds": [1], "limit": 2}]
["REQ", "RAND2", {"kinds": [2], "limit": 2}]
$ cat commands.txt | gnost-cat wss://relay.damus.io
使用 jq 查询 Nostr JSON 事件并选择事件 JSON
$ echo '["REQ", "RAND", {"kinds": [1], "limit": 8}]' |
gnostr-cat wss://relay.damus.io |
jq '.[2]'
$ echo '["REQ", "RAND", {"kinds": [1], "limit": 8}]' |
gnostr-cat wss://relay.damus.io |
jq '.[2].content'
按接收顺序输出唯一(去重)结果(注意:不再对事件进行排序 - 先进先出)
$ echo '["REQ", "RAND", {"kinds": [1], "limit": 8}]' |
gnostr-cat --unique wss://relay.damus.io wss://nostr.ono.re
带有毫秒级的 WebSocket 连接超时
$ echo '["REQ", "RAND", {"kinds": [1], "limit": 2}]' |
gnostr-cat --connect-timeout 250 wss://relay.damus.io
流式 WebSocket 数据(类似于 tail -f)
$ echo '["REQ", "RAND", {"kinds": [1], "limit": 8}]' |
gnostr-cat --stream wss://relay.damus.io
输出信息日志消息,有助于调试
$ echo '["REQ", "RAND", {"kinds": [1], "limit": 8}]' |
RUST_LOG=info gnostr-cat wss://relay.damus.io
从服务器 A 将事件管道传输到服务器 B(当前每次仅限于 1 个事件)
$ echo '["REQ", "RAND", {"limit": 1}]' |
gnostr-cat wss://relay.damus.io |
jq -c 'del(.[1])' |
gnostr-cat wss://nostr.ono.re
从服务器 A 将事件管道传输到服务器 B(对于多个事件,完成时按 ctrl-C
)
$ echo '["REQ", "RAND", {"limit": 3}]' |
gnostr-cat wss://relay.damus.io |
jq -c 'del(.[1])' |
gnostr-cat --stream wss://nostr.ono.re
<ctrl-C>
入门
使用 Cargo 安装(需要 ~/.cargo/bin 在 PATH 中)
$ cargo install gnostr-cat
从源码构建(可能不稳定)
$ git clone https://github.com/gnostr-org/gnostr-cat && cd gnostr-cat
$ cargo build --release
在 Docker 映像中运行
$ docker build -t gnostr-cat .
# Run the the docker image as an executable
$ echo '["REQ", "RAND", {"kinds": [1], "limit": 2}]' | docker run --rm -i gnostr-cat wss://relay.damus.io
checkout websocat
websocat
WebSocket 的 netcat、curl 和 socat。
示例
连接到公共 echo 服务器
$ websocat ws://ws.vi-server.org/mirror
123
123
ABC
ABC
服务和连接
A$ websocat -s 1234
Listening on ws://127.0.0.1:1234/
ABC
123
B$ websocat ws://127.0.0.1:1234/
ABC
123
在 Chromium 中打开一个标签页进行远程调试。
$ 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"}}
代理 TCP 连接到 WebSocket 连接并返回。
$ 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.
广播连接的 WebSocket 客户端之间的所有消息
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
(如果你喜欢这个版本,你可能实际上想使用https://github.com/vi/wsbroad/)
查看更多示例,请参阅moreexamples.md。
特性
- 从命令行连接到并服务WebSocket。
- 执行外部程序,并通过stdin/stdout与WebSocket通信。
- 文本和二进制模式,在行(或空终止的记录)和消息之间进行转换。
- Inetd模式,UNIX套接字(包括Linux上的命名空间抽象名称)。
- 使用TCP或UNIX套接字与Nginx集成。
- 直接使用未认证的SOCKS5服务器连接到WebSocket并监听WebSocket连接。
- 自动重连和连接重用模式。
- 支持Linux、Windows和Mac,提供预构建的可执行文件。
- 具有可覆盖底层传输连接的低级别WebSocket客户端和服务器,例如,调用外部程序作为websocat的传输(用于SSL、代理等)。
安装
安装WebSocat有多种选择。从简单到复杂
- 如果你使用Fedora,可以从Copr安装WebSocat:
sudo dnf copr enable atim/websocat -y && sudo dnf install websocat
- 如果你使用FreeBSD,可以使用以下命令安装WebSocat:
pkg install websocat
。 - 如果你使用Linux Debian或Ubuntu(或其他dpkg-based),请尝试从GitHub releases下载预构建的可执行文件。WebSocat尚未为Debian官方打包。WebSocat的一些旧版本可能也在GitHub releases上提供Debian包文件。
- 如果你使用macOS,你可以
- 下载预构建的可执行文件并将其安装到PATH。
- 安装Rust工具链并执行
cargo install --features=ssl websocat
。如果某个东西因-sys
包而失败,请尝试不带--features=ssl
; - 从源代码构建Websocat(见下文),然后将
target/release/websocat
移动到PATH的某个位置。
Linux(通常和musl)、Windows、OS X和Android的预构建二进制文件可在发布页面上找到。
从源代码构建
- 安装Rust工具链。请注意,由于Websocat v1(即当前稳定版本)的旧依赖项可能因例如 此 而不支持过新的Rust。
cargobuild --release --features=ssl
.- 在
target/
下的某个位置找到可执行文件,例如在target/release/websocat
中。
Rust版本
WebSocat版本 | 最小Rust版本 | 最大Rust版本 |
---|---|---|
1.9 - 1.11 | 1.46 | 可能1.63 |
1.6 - 1.8 | 1.34 | 可能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 | ? | ? |
请注意,使用旧版Rust版本(例如1.46)构建可能需要在构建之前手动将Cargo.lock.legacy
复制到Cargo.lock
。
较早的非异步版本的Websocat可以使用更旧的rustc进行构建。
请注意,由于https://github.com/rust-lang/rust/pull/71274/,旧版本的Websocat如果使用Rust 1.48或更高版本构建可能会出现异常行为。
由于[IP地址表示重构],使用Rust 1.64构建Websocat v1.x系列可能不是一个好主意。它可能会暴露旧依赖中之前隐藏的未定义行为。(在实践中,它似乎只是正常工作 - 但自从我详细检查Websocat以来已经过去很长时间了)。
Android上的SSL
websocat的wss://
可能在Android上失败。作为解决方案,从https://curl.haxx.se/ca/cacert.pem下载证书包,并明确指定它。
SSL_CERT_FILE=cacert.pem /data/local/tmp/websocat wss://echo.websocket.org
或者直接使用--insecure
选项。
文档
基本用法示例在README顶部和--help
消息中提供。更多技巧请参阅moreexamples.md。
有一个所有地址类型和覆盖物的列表。
`websocat --help=long`输出
websocat 1.12.0
Vitaly "_Vi" Shukela <vi0oss@gmail.com>
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
--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
--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]
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
一些说明
- 支持IPv6,根据上下文,用方括号包围您的IP地址或按原样使用。
- Web套接字的使用不是强制的,您可以在两端使用任何规范。
- 通常,二进制流中的一行对应于一个WebSocket文本消息。这可以通过选项进行调整。
限制
- 当文本和二进制WebSocket消息混合时,不太方便。这影响
mirror:
指定符,使其与ws://echo.websocket.org略有不同。有--binary-prefix
、--text-prefix
和--base64
选项来处理二进制和文本的混合。 - 当前版本的Websocat不会接收到关于关闭套接字的任何通知。这使在未使用
-E
或-u
选项或在背压场景下容易发生套接字泄漏。 - 没有集成Readline。建议用户使用
rlwrap
工具包装websocat以获得更方便的CLI。 - 当前版本的Websocat的构建过程没有适当地自动化,且容易出错。
- 如果服务没有同时正确监听IPv4和IPv6,
ws://localhost
可能会失败。如果需要,可以基于ws-c:tcp:
进行解决方案。或者,直接使用ws://127.0.0.1
。
另请参阅
依赖关系
~16–30MB
~483K SLoC