The server
and client
examples demonstrate fetching files using a HTTP-like toy protocol.
- Server (
server.rs
)
The server listens for any client requesting a file. If the file path is valid and allowed, it returns the contents.
Open up a terminal and execute:
$ cargo run --example server ./
- Client (
client.rs
)
The client requests a file and prints it to the console. If the file is on the server, it will receive the response.
In a new terminal execute:
$ cargo run --example client https://localhost:4433/Cargo.toml
where Cargo.toml
is any file in the directory passed to the server.
Result:
The output will be the contents of this README.
Troubleshooting:
If the client times out with no activity on the server, try forcing the server to run on IPv4 by
running it with cargo run --example server -- ./ --listen 127.0.0.1:4433
. The server listens on
IPv6 by default, localhost
tends to resolve to IPv4, and support for accepting IPv4 packets on
IPv6 sockets varies between platforms.
If the client prints failed to process request: failed reading file
, the request was processed
successfully but the path segment of the URL did not correspond to a file in the directory being
served.
The connection.rs
example intends to use the smallest amount of code to make a simple QUIC connection.
The server issues it's own certificate and passes it to the client to trust.
$ cargo run --example connection
This example will make a QUIC connection on localhost, and you should see output like:
[client] connected: addr=127.0.0.1:5000
[server] connection accepted: addr=127.0.0.1:53712
The insecure_connection.rs
example demonstrates how to make a QUIC connection that ignores the server certificate.
$ cargo run --example insecure_connection --features="rustls/dangerous_configuration"
You can have multiple QUIC connections over a single UDP socket. This is especially useful, if you are building a peer-to-peer system where you potentially need to communicate with thousands of peers or if you have a hole punched UDP socket. Additionally, QUIC servers and clients can both operate on the same UDP socket. This example demonstrates how to make multiple outgoing connections on a single UDP socket.
$ cargo run --example single_socket
The expected output should be something like:
[client] connected: addr=127.0.0.1:5000
[server] incoming connection: addr=127.0.0.1:48930
[client] connected: addr=127.0.0.1:5001
[client] connected: addr=127.0.0.1:5002
[server] incoming connection: addr=127.0.0.1:48930
[server] incoming connection: addr=127.0.0.1:48930
Notice how the server sees multiple incoming connections with different IDs coming from the same endpoint.