Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
W

websocat

> 开发工具
Open source

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

8.6K stars0 likes3 views
WebsiteGitHub

About

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

websocat

Netcat, curl and socat for WebSockets.

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:

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 websocat. If something fails with a -sys crate, try with --no-default-features;
  • 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.
  3. Find the executable somewhere under target/, e.g. in target/release/websocat.

Rust versions

Websocat versions Minimal Rust version Maximal Rust version
4.0.0-alpha1 1.84 ?
1.12+ ? ?
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 https://github.com/rust-lang/rust/pull/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
…

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 only connects (or serves) HTTP/1. RFC 8441 or RFC 9220 are not currently supported.
  • 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.
  • Main version (v1) is based on obsolete dependency versions that trigger security warnings and may become tricky to build. There is new version (v4), but is not yet considered stable and has many missing features.

Bindings

  • Node.js: seamapi/node-websocat

See also

  • wstunnel
  • wscat
  • websocketd
  • wsd

Issues· 159 open

View all issuesOpen on GitHub
  • #313

    Does not work on windows "GetSystemTimePreciseAsZFileTime could not be located"

    Updated Sep 12, 2026
  • #312

    关于events.mux在ws中的直接明文暴漏,导致rpcid和approvalid泄漏造成的安全问题

    Updated Aug 14, 2026
  • #25

    Support scoop

    Updated Jun 5, 2026
  • #305

    Drop the musl requirement in the README

    Updated Apr 24, 2026
  • #276

    Websocat1 features missing in Websocat4

    Updated Feb 23, 2026
  • #250

    websocat sometimes doesn't flush pending data, hangs

    Updated Feb 21, 2026
  • #304

    autoreconnect with --preamble

    enhancementUpdated Feb 9, 2026
  • #303

    Proper Errorcode reporting

    enhancementUpdated Jan 21, 2026
  • #282

    maybe add discussions? maybe stats like curl?

    enhancementUpdated Jan 20, 2026
  • #88

    Windows Named Pipe Support

    enhancementUpdated Jan 20, 2026

> Tags

Rustclicommand-linecommand-line-toolcurl

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 30, 2026
Category开发工具
PricingOpen source

> Related tools

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具