use std::time::Duration;
use fastnet::{SecureSocket, SecureEvent};
#[tokio::main]
async fn main() -> std::io::Result<()> {
println!("╔═══════════════════════════════════════╗");
println!("║ Test Crash Client (No Disconnect) ║");
println!("╚═══════════════════════════════════════╝");
println!();
let server_addr = "127.0.0.1:7778".parse().unwrap();
println!("Connecting to {}...", server_addr);
let mut client = SecureSocket::connect(server_addr).await?;
println!("TLS handshake complete!");
println!();
let peer_id = 'wait_connect: loop {
for event in client.poll().await? {
if let SecureEvent::Connected(id) = event {
println!("[+] Connected as peer {}", id);
break 'wait_connect id;
}
}
tokio::time::sleep(Duration::from_millis(10)).await;
};
println!("[>] Sending: \"Test message\"");
client.send(peer_id, 0, b"Test message".to_vec()).await?;
let start = std::time::Instant::now();
'recv: loop {
for event in client.poll().await? {
if let SecureEvent::Data(_, _, data) = event {
let elapsed = start.elapsed();
let response = String::from_utf8_lossy(&data);
println!("[<] Received: \"{}\" (RTT: {:?})", response, elapsed);
break 'recv;
}
}
}
println!();
println!("✋ Now client will wait forever without disconnect (simulating freeze)");
println!(" Note: Automatic timeout detection is disabled by default.");
println!(" To enable timeout detection, configure PeerConfig with a timeout value.");
println!();
loop {
tokio::time::sleep(Duration::from_secs(60)).await;
}
}