Created
August 7, 2017 04:06
-
-
Save dseg/0bbe9ebee788baac0085cba26efaac50 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io::Write; | |
use std::net::{TcpListener, TcpStream}; | |
use std::thread; | |
fn handle_client(mut stream: TcpStream) { | |
thread::spawn(move || { | |
stream.write(b"Hello World\r\n").unwrap(); | |
}); | |
} | |
fn main() { | |
let listener = TcpListener::bind("127.0.0.1:54321").unwrap(); | |
println!("listening started, ready to accept"); | |
for stream in listener.incoming() { | |
match stream { | |
Ok(stream) => { | |
handle_client(stream); | |
} | |
Err(e) => { | |
/* connection failed */ | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment