Crate wtransport_lightyear_patch
source ·Expand description
WebTransport protocol implementation in pure Rust, async-friendly, and API-simple.
For a quick start with this library, refer to Endpoint
.
About WebTransport
WebTransport is a modern protocol built on QUIC and HTTP/3, providing an alternative to HTTP and WebSocket.
It’s designed for efficient client-server communication with low latency and bi-directional multistream data exchange capabilities, making it suitable for a wide range of applications.
WebTransport guarantees secure and reliable communication by leveraging encryption and authentication to protect your data during transmission.
WebTransport offers two key communication channels: streams and datagrams.
Streams
WebTransport streams are communication channels that provide ordered and reliable data transfer.
WebTransport streams allow sending multiple sets of data at once within a single session. Each stream operates independently, ensuring that the order and reliability of one stream do not affect the others.
Streams can be: uni-directional or bi-directional.
Order Preserved, Guaranteed Delivery, Flow-Controlled, Secure (All Traffic Encrypted), and Multiple Independent Streams.
Datagrams
WebTransport datagrams are lightweight and unordered communication channels, prioritizing quick data exchange without guarantees of reliability or sequence.
Unordered, No Guaranteed Delivery, No Flow-Controlled, Secure (All Traffic Encrypted), Independent Messages.
Examples
Explore operational server and client examples below. The elegantly simple yet potent API empowers you to get started with minimal code.
Server
use wtransport::Certificate;
use wtransport::Endpoint;
use wtransport::ServerConfig;
#[tokio::main]
async fn main() -> Result<()> {
let config = ServerConfig::builder()
.with_bind_default(4433)
.with_certificate(Certificate::load("cert.pem", "key.pem").await?)
.build();
let server = Endpoint::server(config)?;
loop {
let incoming_session = server.accept().await;
let incoming_request = incoming_session.await?;
let connection = incoming_request.accept().await?;
// ...
}
}
See repository server example for the complete code.
Client
use wtransport::ClientConfig;
use wtransport::Endpoint;
#[tokio::main]
async fn main() -> Result<()> {
let connection = Endpoint::client(ClientConfig::default())?
.connect("https://localhost:4433")
.await?;
// ...
}
See repository client example for the complete code.
Modules
- Client and server configurations.
- WebTransport connection.
- Datagrams module.
- Endpoint module.
- Errors definitions module.
- quinn
quinn
QUIC transport protocol implementation - Interfaces for sending and receiving data.
- TLS specific configurations.
Structs
- A server TLS certificate.
- Client configuration.
- A WebTransport session connection.
- Entrypoint for creating client or server connections.
- A stream that can only be used to receive data.
- A stream that can only be used to send data.
- Server configuration.