rust编写一个简单http服务器代码
代码语言:rust
代码描述:rust编写一个简单http服务器代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
use std::io::prelude::*; use std::net::TcpListener; use std::net::TcpStream; use std::fs::File; use std::thread; fn main() { let listener = TcpListener::bind("127.0.0.1:8080").unwrap(); for stream in listener.incoming() { let stream = stream.unwrap(); thread::spawn(||{ handle_connection(stream); }); } } fn handle_connection(mut stream: TcpStream) { let mut buffer = [0; 512]; stream.read(&mut buffer).unwrap(); let get = b"GET / HTTP/1.1\r\n"; //逻辑处理 l.........完整代码请登录后点击上方下载按钮下载查看
网友评论0