added basic connection handler

Every connection the server recieves a new handle function is called
This commit is contained in:
Mitchell 2020-04-08 23:15:06 +00:00
parent edcc024363
commit f34b2c5cd7
1 changed files with 9 additions and 1 deletions

View File

@ -1,4 +1,6 @@
use std::net::TcpListener;
use std::net::TcpStream;
use std::io::prelude::*;
fn main(){
let listener = TcpListener::bind("127.0.0.1:6001").unwrap();
@ -6,6 +8,12 @@ fn main(){
for stream in listener.incoming(){
let stream = stream.unwrap();
println!("Connection Established!");
handle_connection(stream);
}
}
fn handle_connection(mut stream: TcpStream){
let mut buffer = [0; 512];
stream.read(&mut buffer).unwrap();
println!("Request: {}", String::from_utf8_lossy(&buffer[..]));
}