Rustでasync_stdを用いて簡易なHTTP Serverを実装する

実装 [package] name = "testing" version = "0.1.0" authors = ["TakesxiSximada <[email protected]>"] edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] futures = "0.3" [dependencies.async-std] version = "1.6" features = ["attributes"] Cargo.toml use async_std::prelude::*; use async_std::net::TcpListener; use async_std::net::TcpStream; use futures::stream::StreamExt; async fn handle_connection(mut stream: TcpStream) { let mut buffer = [0; 1024]; stream.read(&mut buffer).await.unwrap(); let response = "HTTP/1.1 200 OK\r\n\r\naaaaaa\r\n\r\n"; stream.write(response.as_bytes()).await.unwrap(); stream.flush().await.unwrap(); } #[async_std::main] async fn main() { let listener = TcpListener::bind("127.0.0.1:7878").await.unwrap(); listener .incoming() .for_each_concurrent(/*...

 · 1 min · しむどん三度無視