mirror of
https://github.com/rjNemo/tokio-chat-server
synced 2026-06-12 12:16:38 +00:00
basic echo server
This commit is contained in:
parent
721b3fa937
commit
59120da277
1 changed files with 11 additions and 1 deletions
12
src/main.rs
12
src/main.rs
|
|
@ -1,4 +1,14 @@
|
||||||
|
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||||
|
use tokio::net::TcpListener;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn 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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue