#4 handle connection
This commit is contained in:
parent
28d9efa7e8
commit
727cc7b1a7
1 changed files with 9 additions and 2 deletions
11
src/main.rs
11
src/main.rs
|
|
@ -1,9 +1,16 @@
|
||||||
use std::net::TcpListener;
|
use std::io::Read;
|
||||||
|
use std::net::{TcpListener, TcpStream};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let listener = TcpListener::bind("127.0.0.1:7878").unwrap();
|
let listener = TcpListener::bind("127.0.0.1:7878").unwrap();
|
||||||
for stream in listener.incoming() {
|
for stream in listener.incoming() {
|
||||||
let stream = stream.unwrap();
|
let stream = stream.unwrap();
|
||||||
println!("Connection established!");
|
handle_connection(stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn handle_connection(mut stream: TcpStream) {
|
||||||
|
let mut buffer = [0; 1024];
|
||||||
|
stream.read(&mut buffer).unwrap();
|
||||||
|
println!("Request: {}", String::from_utf8_lossy(&buffer[..]));
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue