netherrack/io/network/
mod.rspub mod game_connection;
use self::game_connection::GameConnection;
pub mod deque_buffer;
pub mod packet;
use std::net::TcpListener;
use std::thread;
fn start_listening(port: u16) -> Result<TcpListener, &'static str> {
let listener = TcpListener::bind(("127.0.0.1", port));
if listener.is_ok() {
return Ok(listener.unwrap());
} else {
return Err("Could not listen on requested port");
}
}
pub fn start_network() {
let listener = start_listening(25565);
if listener.is_err() {
error!("Could not start listening on port {}", 25565);
}
let listener = listener.unwrap();
for stream in listener.incoming() {
match stream {
Ok(stream) => {
thread::spawn(move || {
GameConnection::new(stream).start_listening()
});
}
Err(e) => {
error!("Could not accept a new stream: {}", e);
}
}
}
drop(listener);
}