You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.rs 665B

123456789101112131415161718192021222324252627
  1. use std::net::{TcpStream, TcpListener};
  2. use std::io::prelude::*;
  3. fn main() {
  4. let listener = TcpListener::bind("127.0.0.1:26382").unwrap();
  5. for stream in listener.incoming() {
  6. let stream = stream.unwrap();
  7. handle_connecton(stream);
  8. }
  9. }
  10. fn handle_connecton(mut stream: TcpStream) {
  11. let mut buffer = [0; 512];
  12. stream.read(&mut buffer).unwrap();
  13. let contents = fs::read_to_string("hello.html").unwrap();
  14. let response = format!("HTTP/1.1 200 OK\r\n\r\n{}", contents);
  15. stream.write(response.as_bytes()).unwrap();
  16. stream.flush().unwrap();
  17. // println!("Request: {}", String::from_utf8_lossy(&buffer[..]));
  18. }