| 4 | |
| 5 | #[wstd::main] |
| 6 | async fn main() -> io::Result<()> { |
| 7 | let listener = TcpListener::bind("127.0.0.1:8080").await?; |
| 8 | println!("Listening on {}", listener.local_addr()?); |
| 9 | println!("type `nc localhost 8080` to create a TCP client"); |
| 10 | |
| 11 | let mut incoming = listener.incoming(); |
| 12 | while let Some(stream) = incoming.next().await { |
| 13 | let stream = stream?; |
| 14 | println!("Accepted from: {}", stream.peer_addr()?); |
| 15 | wstd::runtime::spawn(async move { |
| 16 | // If echo copy fails, we can ignore it. |
| 17 | let _ = io::copy(&stream, &stream).await; |
| 18 | }) |
| 19 | .detach(); |
| 20 | } |
| 21 | Ok(()) |
| 22 | } |