use nexio::net::TcpListener;
fn main() -> std::io::Result<()> {
nexio::block_on(async {
let listener = TcpListener::bind(("127.0.0.1", 7878)).await?;
println!("echo server listening on {}", listener.local_addr()?);
loop {
let stream = listener.accept().await?;
drop(nexio::spawn(async move {
let mut buf = Vec::with_capacity(4096);
loop {
let (res, b) = stream.read(buf).await;
buf = b;
match res {
Ok(0) | Err(_) => break,
Ok(_) => {
let (res, b) = stream.write_all(buf).await;
buf = b;
if res.is_err() {
break;
}
}
}
}
}));
}
})
}