Last active
January 8, 2018 12:29
-
-
Save davidrhyswhite/aaf9087141664c8feba5 to your computer and use it in GitHub Desktop.
Simple TCP Server in Rust
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::{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