Skip to content

Instantly share code, notes, and snippets.

@davidrhyswhite
Last active January 8, 2018 12:29
Show Gist options
  • Save davidrhyswhite/aaf9087141664c8feba5 to your computer and use it in GitHub Desktop.
Save davidrhyswhite/aaf9087141664c8feba5 to your computer and use it in GitHub Desktop.
Simple TCP Server in Rust
use std::io::{TcpListener, TcpStream};
use std::io::{Acceptor, Listener};
use std::thread::Thread;
fn main() {
let mut acceptor = TcpListener::bind("127.0.0.1:3000").unwrap().listen().unwrap();
println!("Listening on 3000");
for stream in acceptor.incoming() {
match stream {
Err(_) => {}
Ok(stream) => Thread::spawn(move|| {
let mut s: TcpStream = stream;
s.write(b"Hello World\r").unwrap();
}).detach()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment