-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use commandline args to run rserver logic added
- Loading branch information
1 parent
3ca97e4
commit 59a7a49
Showing
1 changed file
with
30 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,35 @@ | ||
mod lib; | ||
use std::env; | ||
|
||
fn main() { | ||
let (server_host, server_port) = ("127.0.0.1", 80); | ||
/* | ||
let us declare default local server host and sever port | ||
that will be used in case not all commandline args are passed . | ||
*/ | ||
let (mut server_host, mut server_port) = ("127.0.0.1", 80); | ||
// let us add logic to get local server host and sever port from command line. | ||
// RServer will run at the input server host and server port. | ||
let args = env::args().collect::<Vec<String>>(); // args is a Vector of String | ||
// let us check command line argument length , it should be 3 as 1st argument is the command used to invoke the program | ||
if args.len() < 3 { | ||
println!("Error - Not enough arguments supplied.\nPlease specify local server host and port as command-line arguments."); | ||
println!("Using default host '{}' and port '{}'.", server_host, server_port); | ||
} else { | ||
// First assign the server host | ||
server_host = &args[1]; | ||
// Second assign the | ||
server_port = match args[2].trim().parse() { | ||
Ok(num) => num, | ||
Err(_) => { // handle error and continue the program | ||
println!("Error - Pass port as number."); | ||
println!("Using default port '{}'", server_port); | ||
// return default port value | ||
server_port | ||
} | ||
}; | ||
|
||
} | ||
// println!("server_host: {}", server_host); | ||
// println!("server_port: {}", server_port); | ||
lib::start_server(server_host, server_port); | ||
} |