Browse Source

Add response

master
Noelle 4 years ago
parent
commit
9d0099df14
1 changed files with 17 additions and 2 deletions
  1. 17
    2
      src/main.rs

+ 17
- 2
src/main.rs View File

use std::net::TcpListener;
use std::net::{TcpStream, TcpListener};
use std::io::prelude::*;



fn main() { fn main() {
let listener = TcpListener::bind("127.0.0.1:26382").unwrap(); let listener = TcpListener::bind("127.0.0.1:26382").unwrap();
for stream in listener.incoming() { for stream in listener.incoming() {
let stream = stream.unwrap(); let stream = stream.unwrap();


println!("Connection established!");
handle_connecton(stream);
} }
} }

fn handle_connecton(mut stream: TcpStream) {
let mut buffer = [0; 512];

stream.read(&mut buffer).unwrap();

let response = "HTTP/1.1 200 OK\r\n\r\n";
stream.write(response.as_bytes()).unwrap();

stream.flush().unwrap();

// println!("Request: {}", String::from_utf8_lossy(&buffer[..]));
}

Loading…
Cancel
Save