wtx 0.3.3

Implementations of web communication protocols
Documentation
wtx-0.3.3 has been yanked.

WTX

CI crates.io Documentation License Rustc

Intended to group 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.

fastwebsockets served as an initial inspiration for the skeleton of this implementation so thanks to the authors.

use wtx::{Stream, web_socket::{FrameBufferVec, FrameVecMut, OpCode, WebSocketClientOwned}};

pub async fn handle_client_frames(ws: &mut WebSocketClientOwned<impl Stream>) -> wtx::Result<()> {
  let fb = &mut FrameBufferVec::default();
  loop {
    let frame = match ws.read_msg(fb).await {
      Err(err) => {
        println!("Error: {err}");
        ws.write_frame(FrameVecMut::new_fin(fb.into(), 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.