add QUIC client
parent
937cc65c70
commit
fe2040706b
|
@ -0,0 +1,35 @@
|
||||||
|
use quic_demo::prelude::*;
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main () -> anyhow::Result <()> {
|
||||||
|
tracing_subscriber::fmt::init ();
|
||||||
|
|
||||||
|
let server_cert = tokio::fs::read ("quic_server.crt").await?;
|
||||||
|
let server_addr = "127.0.0.1:30380".parse ()?;
|
||||||
|
let endpoint = make_client_endpoint ("0.0.0.0:0".parse ()?, &[&server_cert])?;
|
||||||
|
|
||||||
|
debug! ("Connecting to relay server");
|
||||||
|
|
||||||
|
let quinn::NewConnection {
|
||||||
|
connection,
|
||||||
|
..
|
||||||
|
} = endpoint.connect (&server_addr, "localhost")?.await?;
|
||||||
|
|
||||||
|
debug! ("Connecting to end server");
|
||||||
|
|
||||||
|
let (mut send, mut recv) = connection.open_bi ().await?;
|
||||||
|
|
||||||
|
let mut buf = vec! [0u8; 65_536];
|
||||||
|
let mut send_interval = tokio::time::interval (Duration::from_millis (1000));
|
||||||
|
// send_interval.set_missed_tick_behavior (tokio::time::MissedTickBehavior::Skip);
|
||||||
|
loop {
|
||||||
|
send_interval.tick ().await;
|
||||||
|
|
||||||
|
send.write_all (b"Hi!\n").await?;
|
||||||
|
let bytes_read = recv.read (&mut buf).await?.ok_or_else (|| anyhow::anyhow! ("Server or relay closed connection"))?;
|
||||||
|
let buf_slice = &buf [0..bytes_read];
|
||||||
|
|
||||||
|
let s = std::str::from_utf8 (buf_slice)?;
|
||||||
|
println! ("Received: `{}`", s);
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,7 +21,7 @@ async fn main () -> anyhow::Result <()> {
|
||||||
|
|
||||||
let mut buf = vec! [0u8; 65_536];
|
let mut buf = vec! [0u8; 65_536];
|
||||||
while let Some (bytes_read) = recv.read (&mut buf).await? {
|
while let Some (bytes_read) = recv.read (&mut buf).await? {
|
||||||
let s = format! ("bytes_read: {}\n", bytes_read);
|
let s = format! ("bytes_read: {}", bytes_read);
|
||||||
send.write_all (s.as_bytes ()).await?;
|
send.write_all (s.as_bytes ()).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
pub use std::{
|
||||||
|
time::Duration,
|
||||||
|
};
|
||||||
|
|
||||||
pub use futures_util::StreamExt;
|
pub use futures_util::StreamExt;
|
||||||
pub use tracing::{
|
pub use tracing::{
|
||||||
debug,
|
debug,
|
||||||
|
|
|
@ -5,7 +5,10 @@ use quinn::{
|
||||||
Certificate, CertificateChain, ClientConfig, ClientConfigBuilder, Endpoint, Incoming,
|
Certificate, CertificateChain, ClientConfig, ClientConfigBuilder, Endpoint, Incoming,
|
||||||
PrivateKey, ServerConfig, ServerConfigBuilder, TransportConfig,
|
PrivateKey, ServerConfig, ServerConfigBuilder, TransportConfig,
|
||||||
};
|
};
|
||||||
use std::{error::Error, net::SocketAddr, sync::Arc};
|
use std::{
|
||||||
|
net::SocketAddr,
|
||||||
|
sync::Arc,
|
||||||
|
};
|
||||||
|
|
||||||
/// Constructs a QUIC endpoint configured for use a client only.
|
/// Constructs a QUIC endpoint configured for use a client only.
|
||||||
///
|
///
|
||||||
|
|
Loading…
Reference in New Issue