Skip to content

Instantly share code, notes, and snippets.

@dseg
Created August 7, 2017 04:06
Show Gist options
  • Save dseg/0bbe9ebee788baac0085cba26efaac50 to your computer and use it in GitHub Desktop.
Save dseg/0bbe9ebee788baac0085cba26efaac50 to your computer and use it in GitHub Desktop.
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