From 727cc7b1a7f311681f4b6358887c86e16e5661b8 Mon Sep 17 00:00:00 2001 From: Shautvast Date: Fri, 6 Feb 2026 15:34:38 +0100 Subject: [PATCH] #4 handle connection --- src/main.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index fe7c395..ac066fe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,16 @@ -use std::net::TcpListener; +use std::io::Read; +use std::net::{TcpListener, TcpStream}; fn main() { let listener = TcpListener::bind("127.0.0.1:7878").unwrap(); 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; 1024]; + stream.read(&mut buffer).unwrap(); + println!("Request: {}", String::from_utf8_lossy(&buffer[..])); +}