Skip to content

Instantly share code, notes, and snippets.

@sproctor
Last active July 24, 2017 19:27
Show Gist options
  • Save sproctor/8f6271287d3fb410015fb9f6e7e75715 to your computer and use it in GitHub Desktop.
Save sproctor/8f6271287d3fb410015fb9f6e7e75715 to your computer and use it in GitHub Desktop.
colony working draft
use std::io::Write;
use std::net::TcpListener;
use std::net::TcpStream;
use std::thread;
fn main() {
println!("Creating server");
// let ip = Ipv4Addr::new(127, 0, 0, 1);
let port = 9000;
let host = "127.0.0.1";
let listener = TcpListener::bind((host, port)).unwrap();
println!("Listener bound, ready to accept connections");
for stream in listener.incoming() {
thread::spawn(|| { handle_client(stream.unwrap()); });
}
}
fn handle_client(mut stream : TcpStream) {
let _ = stream.write(b"Welcome to Colony!\r\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment