WebTransport protocol, pure-rust, async-friendly.
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.
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.
```rust
async fn main() -> Result<(), Error> { let config = ServerConfig::builder() .withbindaddress(SocketAddr::new(Ipv6Addr::LOCALHOST.into(), 4433)) .with_certificate(Certificate::load("cert.pem", "key.pem")?) .build();
let server = Endpoint::server(config)?;
println!("Waiting for incoming connections...");
loop {
let incoming_request = server.accept().await?;
tokio::spawn(async move {
println!("Incoming request...");
let session_request = incoming_request.await?;
println!("Path requested: {}", session_request.path());
let connection = session_request.accept().await?;
let stream = connection.accept_bi().await?
// ...
});
}
} ```
bash
git clone https://github.com/BiagioFesta/wtransport.git
bash
cd wtransport/
bash
cargo run --example gencert
This will generate cert.pem
and key.pem
in the current working directory.
Moreover, the program will also output the fingerprint of the certificate. Something like this:
Certificate generated
Fingerprint: OjyqTe//WoGnvBrgiO37tkOQJyuN1r7hhyBzwX0gotg=
Please take note of the fingerprint, as you will need it to verify the certificate on the client side.
bash
cargo run --example server
Latest versions of Google Chrome started supporting some implementations of the protocol.
Since the generated certificate is self-signed, it cannot be directly accepted by the browser at the moment.
In order to allow the local certificate, you need to launch Google Chrome with two additional options:
google-chrome \
--origin-to-force-quic-on=localhost:4433 \
--ignore-certificate-errors-spki-list=FINGERPRINT
Replace FINGERPRINT
with the value obtained in step 1.
For example, OjyqTe//WoGnvBrgiO37tkOQJyuN1r7hhyBzwX0gotg=
.
Open the website https://webtransport.day/ on Google Chrome instace. Use the URL: https://localhost:4433
, and click on Connect.
Enjoy!