13 releases

0.1.12 Mar 27, 2024
0.1.11 Feb 17, 2024
0.1.10 Dec 23, 2023
0.1.8 Oct 31, 2023
0.1.0 May 25, 2023

#128 in Network programming

Download history 81/week @ 2024-01-04 133/week @ 2024-01-11 120/week @ 2024-01-18 162/week @ 2024-01-25 588/week @ 2024-02-01 280/week @ 2024-02-08 494/week @ 2024-02-15 597/week @ 2024-02-22 562/week @ 2024-02-29 247/week @ 2024-03-07 241/week @ 2024-03-14 371/week @ 2024-03-21 375/week @ 2024-03-28 1046/week @ 2024-04-04 599/week @ 2024-04-11 450/week @ 2024-04-18

2,588 downloads per month
Used in 9 crates (6 directly)

MIT/Apache

390KB
8K SLoC

WTransport Logo

Documentation Crates.io CI Chat 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.
  • 🌐 Native Browser Support: WebTransport is natively supported in modern web browsers, ensuring seamless integration and enhanced performance for web applications.

Check Library Documentation

Notes

Please be aware that WebTransport is still a draft and not yet standardized. The WTransport library, while functional, is not considered completely production-ready. It should be used with caution and may undergo changes as the WebTransport specification evolves.

Simple API

Server Client
#[tokio::main]
async fn main() -> Result<()> {
    let config = ServerConfig::builder()
        .with_bind_default(4433)
        .with_identity(&identity)
        .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?;
    // ...
}
#[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?;
    // ...
}

Browser Integration

WebTransport is supported in modern browsers, enhancing the capabilities of web applications.

For instance, you can create a native browser WebTransport client connecting to a Rust server using the following JavaScript code:

// Create a WebTransport instance connecting to the Rust server
let transport = new WebTransport('https://[::1]:4433');
await transport.ready;

// Create a bidirectional stream
let stream = await transport.createBidirectionalStream();

// Send data from the client to the server
await stream.writable.getWriter().write(new TextEncoder().encode("hello"));

// Read data reply from the server
let data = await stream.readable.getReader().read();
console.log(data);

Check out the W3C WebTransport API documentation for more details and to explore the full capabilities of WebTransport in the browser.

Getting Started

Clone the Repository

git clone https://github.com/BiagioFesta/wtransport.git
cd wtransport/

Run Full Example

The examples/full.rs is a minimal but complete server example that demonstrates the usage of WebTransport.

You can run this example using Cargo, Rust's package manager, with the following command:

cargo run --example full

This example initiates an echo WebTransport server that can receive messages. It also includes an integrated HTTP server.

Open Google Chrome and navigate to the page http://127.0.0.1:8080.

Examples

Other Languages

WTransport has bindings for the following languages:

Dependencies

~16–26MB
~510K SLoC