diff --git a/Cargo.lock b/Cargo.lock index a0c0e4b..56b9f87 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -64,6 +64,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + [[package]] name = "bytes" version = "1.2.1" @@ -171,6 +177,18 @@ version = "0.2.132" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" +[[package]] +name = "local-ip-address" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74d6f43d42d775afa8073bfa6aba569b340a3635efa8c9f7702c9c6ed209692f" +dependencies = [ + "libc", + "neli", + "thiserror", + "windows-sys", +] + [[package]] name = "lock_api" version = "0.4.7" @@ -202,6 +220,7 @@ version = "0.1.0" dependencies = [ "color-eyre", "env_logger", + "local-ip-address", "log", "tokio", ] @@ -227,6 +246,16 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "neli" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9053554eb5dcb7e10d9cdab1206965bde870eed5d0d341532ca035e3ba221508" +dependencies = [ + "byteorder", + "libc", +] + [[package]] name = "num_cpus" version = "1.13.1" @@ -397,6 +426,26 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "thiserror" +version = "1.0.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5f6586b7f764adc0231f4c79be7b920e766bb2f3e51b3661cdb263828f19994" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12bafc5b54507e0149cdf1b145a5d80ab80a90bcd9275df43d4fff68460f6c21" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "thread_local" version = "1.1.4" diff --git a/Cargo.toml b/Cargo.toml index b87505a..eb1aa89 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,3 +10,4 @@ color-eyre = "0.6.1" tokio = { version = "1.18.2", features = ["full"] } log = "0.4.17" env_logger = "0.9.0" +local-ip-address = "0.4.7" diff --git a/README.md b/README.md index 842e23e..bdf6a6c 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,8 @@ A wannabe discord clone but currently only support websocket real time chatting ### Development - Run the server with `cargo run` or `RUST_LOG=debug cargo run` to run with debug. ### Production -- Run the binary with `minh_cord {LOCAL_IP_ADDRESS}`. +- Run the binary with `./minh_cord`. ## Connecting to the server -- Get your local IP address of the machine you're running the server on: i.e `192.168.0.100` - Run the server with the above commands. -- Run `telnet 192.168.0.100` from a client to connect to the server. +- Run `telnet {SERVER_INTERNAL_IP_ADDRESS}` from a client to connect to the server. diff --git a/src/main.rs b/src/main.rs index 061d83c..1cd7c2b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,17 +5,15 @@ use tokio::{ sync::broadcast, }; use log::debug; -use std::env; +use local_ip_address::local_ip; #[tokio::main] async fn main() -> Result<(), Report> { - let args: Vec = env::args().collect(); - env_logger::init(); // Setup the Environment setup()?; - let ip_address = &args[1]; + let ip_address = local_ip().unwrap(); // Set up a TCP listener to listen for incoming tcp requests at the ip address that is passed from the command line let listener = TcpListener::bind(format!("{ip_address}:8080")).await.unwrap();