DEV Community

Cover image for WTransport - WebTransport library in Rust 🦀
Tausif
Tausif

Posted on • Edited on

2 1 1

WTransport - WebTransport library in Rust 🦀

WebTransport is a modern update to Websockets, transmitting data between client and server using http3.

WTransport is an implementation http3 WebTransport written in Rust.

GitHub logo BiagioFesta / wtransport

Async-friendly WebTransport implementation in Rust

WTransport Logo

Documentation Crates.io CI Zulip chat

WTransport

WebTransport protocol, pure-rust, async-friendly.

Introduction

WebTransport is a new protocol being developed to enable low-latency, bidirectional communication between clients and servers over the web It aims to address the limitations of existing protocols like HTTP and WebSocket by offering a more efficient and flexible transport layer.

Benefits of WebTransport

  • 🚀 Low latency: WebTransport is designed to minimize latency, making it suitable for real-time applications such as gaming, video streaming, and collaborative editing.
  • 🔄 Bidirectional communication: WebTransport allows simultaneous data exchange between the client and server, enabling efficient back-and-forth communication without the need for multiple requests.
  • 🔀 Multiplexing: With WebTransport, multiple streams can be multiplexed over a single connection, reducing overhead and improving performance.
  • 🔒 Security: WebTransport benefits from the security features provided by the web platform, including transport encryption and same-origin policy.

Check Library Documentation

Notes

Please be aware that WebTransport…

Benefits of WebTransport:

  • 🚀 Low latency: WebTransport is designed to minimize latency, making it suitable for real-time applications such as gaming, video streaming, and collaborative editing.
  • 🔄 Bidirectional communication: WebTransport allows simultaneous data exchange between the client and server, enabling efficient back-and-forth communication without the need for multiple requests.
  • 🔀 Multiplexing: With WebTransport, multiple streams can be multiplexed over a single connection, reducing overhead and improving performance.
  • 🔒 Security: WebTransport benefits from the security features provided by the web platform, including transport encryption and same-origin policy.

WTransport's simple API

WTransport comes with both server and client implementaton. Here is how it looks:

Server

#[tokio::main]
async fn main() -> Result<()> {
    let config = ServerConfig::builder()
        .with_bind_default(4433)
        .with_certificate(certificate)
        .build();

    let connection = Endpoint::server(config)?
        .accept()
        .await     // Awaits connection
        .await?    // Awaits session request
        .accept()  // Accepts request
        .await?;   // Awaits ready session

    let stream = connection.accept_bi().await?;
    // ...
}
Enter fullscreen mode Exit fullscreen mode

Client

#[tokio::main]
async fn main() -> Result<()> {
    let config = ClientConfig::default();

    let connection = Endpoint::client(config)?
        .connect("https://[::1]:4433")
        .await?;

    let stream = connection.open_bi().await?.await?;
    // ...
}
Enter fullscreen mode Exit fullscreen mode

Get Started

The repo has a full example, where you launch a server and a chrome instance to communicate with each other over h3 WebTransport protocol. Here you can find it:
https://github.com/BiagioFesta/wtransport/blob/master/wtransport/examples/full.rs

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs