MCPcopy Index your code
hub / github.com/PrivateRookie/ws-tool

github.com/PrivateRookie/ws-tool @v0.9.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.9.0 ↗ · + Follow
314 symbols 677 edges 35 files 178 documented · 57%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

ws-tool

An easy to use websocket client/server toolkit, supporting blocking/async IO.

feature matrix

IO type split proxy tls buffered stream deflate use as client use as server
blocking
async

For tls connection, ws-tool support both native-tls and rustls, ws-tool also support simd unmask(need simd feature in nightly build) and simd utf checking for faster unmask & utf8 string checking.

It's tested by autobaha test suit. see test report of 4 example

usage

Every example can be run with

cargo run --example <example_name> --all-features

command.

See examples/server for building a websocket echo server with self signed certs.

  • examples/echo demonstrates how to connect to a server.
  • echo_server demonstrates how to setup a server.
  • deflate_client and deflate_server demostrate how to enable permessage-deflate extension
  • binance demostrates how to connect to wss server via http/socks proxy
  • autobaha_xxx_client are autobaha test suit client
  • bench_xxx are benchmark server examples, showing how to control read/write buffer or other low level config

run autobahn testsuite

start test server

./script/start_autobahn_server.sh

run test on other terminal

cargo ac
cargo aac
cargo adc
cargo aadc

report files should be under test_reports dir.

performance

Performance is a complex issue, and a single performance indicator is not enough to describe the performance of a certain library. Here we only compare QPS as a brief description of ws-tool performance

My test machine is i9-12900k and 32GB, 3200MHz ddr4, and load test client is load_test

Roughly compare with EchoSever example, tungstenite

The following are the benchmark(1 connection only) results, there is no tungstenite with buffered stream test case, because there tungstenite does not work well with buffered stream. ws-tool test cases are all built with simd feature enabled, tokio runtime use current_thread flavor.

300 bytes payload size, 100000000 messages

cargo lt -- -p 300 --count 100000 -t 1 <url>
server count Duration(ms) Message/sec
uWebSocket 100000000 16798 5953089.65
tungstenite 100000000 19905 5023863.35
bench_server(no buffer) 100000000 42395 2358768.72
bench_server(8k) 100000000 16541 6045583.70
bench_async_server(no buffer) 100000000 45774 2184646.31
bench_async_server(8k) 100000000 16360 6112469.44

1M bytes payload size, 100000 messages

cargo lt -- -p 1048576 --count 100 -t 1 <url>
server count Duration(ms) Message/sec
uWebSocket 100000 34900 2865.33
tungstenite 100000 38745 2580.98
bench_server(no buffer) 100000 29854 3349.63
bench_server(8k) 100000 28887 3461.76
bench_async_server(no buffer) 100000 29280 3415.30
bench_async_server(8k) 100000 29384 3403.21

you can try more combinations with load_test tool

http header style

for multiple extension/protocol, ws-tool prefer to use multiple header with the same name, instead of "," separated value. but ws-tool still try to parse extension/protocol from "," separated header value.

REF

Extension points exported contracts — how you extend this code

DefaultCode (Interface)
a trait that tells ws-tool corresponding opcode of custom type [7 implementers]
src/lib.rs
Split (Interface)
split something into two parts [5 implementers]
src/codec/mod.rs
AsyncRW (Interface)
(no doc) [1 implementers]
src/stream.rs
Context (Interface)
(no doc) [2 implementers]
src/codec/deflate/mod.rs

Core symbols most depended-on inside this repo

send
called by 35
src/codec/frame/blocking.rs
payload
called by 30
src/frame.rs
receive
called by 30
src/codec/frame/blocking.rs
header
called by 29
src/lib.rs
extend_from_slice
called by 18
src/frame.rs
ctor_header
called by 15
src/frame.rs
connect
called by 13
src/lib.rs
into
called by 12
src/lib.rs

Shape

Method 175
Function 69
Class 59
Enum 7
Interface 4

Languages

Rust100%

Modules by API surface

src/frame.rs43 symbols
src/protocol.rs27 symbols
src/codec/deflate/mod.rs25 symbols
src/lib.rs22 symbols
src/codec/frame/mod.rs20 symbols
src/codec/frame/non_blocking.rs19 symbols
src/codec/frame/blocking.rs16 symbols
src/codec/deflate/non_blocking.rs16 symbols
src/stream.rs13 symbols
src/codec/deflate/blocking.rs13 symbols
src/codec/text/non_blocking.rs9 symbols
src/codec/text/blocking.rs9 symbols

For agents

$ claude mcp add ws-tool \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact