summaryrefslogtreecommitdiffstats
path: root/src/bin/server/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/server/main.rs')
-rw-r--r--src/bin/server/main.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/bin/server/main.rs b/src/bin/server/main.rs
new file mode 100644
index 0000000..2c6e1dc
--- /dev/null
+++ b/src/bin/server/main.rs
@@ -0,0 +1,23 @@
1mod args;
2mod handler;
3
4use std::net::TcpListener;
5use std::thread;
6
7fn main() {
8 let args = args::parse_args();
9 let listener = match TcpListener::bind(format!("{}:{}", args.ip, args.port)) {
10 Ok(l) => l,
11 Err(e) => {
12 eprintln!("Failed to bind to {}:{}: {}", args.ip, args.port, e);
13 std::process::exit(1);
14 }
15 };
16 println!("Server listening on {}", listener.local_addr().unwrap());
17 for stream in listener.incoming() {
18 let stream = stream.unwrap();
19 thread::spawn(move || {
20 handler::handle_client(stream);
21 });
22 }
23}