#client #io #network #server #websocket

no-std bin+lib wtx

A collection of different web transport implementations

14 releases (9 breaking)

0.11.0 Oct 25, 2023
0.9.0 Oct 6, 2023

#9 in #network-server

Download history 40/week @ 2023-08-13 157/week @ 2023-08-20 42/week @ 2023-08-27 7/week @ 2023-09-03 19/week @ 2023-09-10 17/week @ 2023-09-17 56/week @ 2023-09-24 63/week @ 2023-10-01 39/week @ 2023-10-08 62/week @ 2023-10-15 85/week @ 2023-10-22 32/week @ 2023-10-29 23/week @ 2023-11-05 27/week @ 2023-11-12 32/week @ 2023-11-19 60/week @ 2023-11-26

143 downloads per month

Apache-2.0

145KB
4K SLoC

WTX

CI crates.io Documentation License Rustc

A collection of different web transport implementations.

WebSocket

Provides low and high level abstractions to dispatch frames, as such, it is up to you to implement Stream with any desired logic or use any of the built-in strategies through the selection of features.

use wtx::{
  Stream,
  rng::Rng,
  web_socket::{
    FrameBufferVec, FrameMutVec, FrameVecMut, compression::NegotiatedCompression, OpCode,
    WebSocketClientOwned
  }
};

pub async fn handle_client_frames(
  fb: &mut FrameBufferVec,
  ws: &mut WebSocketClientOwned<impl NegotiatedCompression, impl Rng, impl Stream>
  ) -> wtx::Result<()> {
  loop {
    let frame = match ws.read_frame(fb).await {
      Err(err) => {
        println!("Error: {err}");
        ws.write_frame(&mut FrameMutVec::new_fin(fb, OpCode::Close, &[])?).await?;
        break;
      }
      Ok(elem) => elem,
    };
    match (frame.op_code(), frame.text_payload()) {
      (_, Some(elem)) => println!("{elem}"),
      (OpCode::Close, _) => break,
      _ => {}
    }
  }
  Ok(())
}

See the examples directory for more suggestions.

Autobahn

All the fuzzingclient/fuzzingserver tests provided by the Autobahn|Testsuite project are passing and the full reports can found at https://c410-f3r.github.io/wtx.

Compression

The "permessage-deflate" extension, described in RFC-7692, is the only supported compression format and is backed by the fastest compression library available at the current time, which is "zlib-ng". It also means that a C compiler is required to use such a feature.

Performance

There are mainly 2 things that impact performance, the chosen runtime and the number of pre-allocated bytes. Specially for servers that have to create a new WebSocket instance for each handshake, pre-allocating a high number of bytes for short-lived or low-transfer connections can have a negative impact.

Benchmark

If you disagree with any of the above numbers, feel free to checkout wtx-bench to point any misunderstandings or misconfigurations. A more insightful analysis is available at https://c410-f3r.github.io/thoughts/the-fastest-websocket-implementation/.

Dependencies

~0–16MB
~188K SLoC