basic echo server

This commit is contained in:
Ruidy 2021-09-01 14:13:21 +02:00
parent 721b3fa937
commit 59120da277

View file

@ -1,4 +1,14 @@
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::TcpListener;
#[tokio::main]
async fn main() {
println!("Hello, world!");
let listener = TcpListener::bind("localhost:8080").await.unwrap();
let (mut socket, _addr) = listener.accept().await.unwrap();
loop {
let mut buffer = [0u8; 1024];
let bytes_read = socket.read(&mut buffer).await.unwrap();
socket.write_all(&buffer[..bytes_read]).await.unwrap();
}
}