|
|
@@ -1,3 +1,31 @@ |
|
|
|
use std::{ |
|
|
|
io::{prelude::*, BufReader}, |
|
|
|
net::{TcpListener, TcpStream}, |
|
|
|
}; |
|
|
|
use std::io::Lines; |
|
|
|
|
|
|
|
fn main() { |
|
|
|
println! ("server"); |
|
|
|
let listener = TcpListener::bind("127.0.0.1:7878").unwrap(); |
|
|
|
|
|
|
|
for stream in listener.incoming() { |
|
|
|
let stream = stream.unwrap(); |
|
|
|
|
|
|
|
handle_connection(stream); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
fn handle_connection(mut stream: TcpStream) { |
|
|
|
let mut stream2: TcpStream = stream.try_clone().unwrap(); |
|
|
|
let buf_reader: BufReader<&mut TcpStream> = BufReader::new(&mut stream); |
|
|
|
let request: Lines<BufReader<&mut TcpStream>> = buf_reader.lines(); |
|
|
|
|
|
|
|
println!("Request: {:#?}", request); |
|
|
|
|
|
|
|
for elem in request |
|
|
|
{ |
|
|
|
let s = elem.unwrap(); |
|
|
|
println!("{:?}", s); |
|
|
|
stream2.write(s.as_bytes()).unwrap(); |
|
|
|
stream2.write_all(b"\n").unwrap(); |
|
|
|
} |
|
|
|
} |