main.rs 1.32 KB
Newer Older
1
#![feature(type_ascription)]
2
#![feature(stmt_expr_attributes)]
3 4
use std::env;

5 6
static PROTOCOL: &'static str = "0.1";

7 8 9 10 11 12 13 14 15 16 17
pub mod client;
pub mod server;

fn main() {
    let args: Vec<String> = env::args().collect();
    if args.len() == 2 {
        ///////////////////////////////////////////////////////////////////////
        //                           Server opened                           //
        ///////////////////////////////////////////////////////////////////////
        println!("Opening server on port {}", args[1]);
        // serveur(args[1].clone());
Phuntsok Drak-pa's avatar
Phuntsok Drak-pa committed
18
        let mut serv = String::from("0.0.0.0:");
19 20
        serv.push_str(&args[1]);
        server::serveur(serv);
21 22 23 24 25
    } else if args.len() == 3 {
        ///////////////////////////////////////////////////////////////////////
        //                           Client opened                           //
        ///////////////////////////////////////////////////////////////////////
        println!("Client connecting on server {}:{}", args[1], args[2]);
Phuntsok Drak-pa's avatar
Phuntsok Drak-pa committed
26 27 28 29 30
        let mut serv: String = if args[1] == "localhost" {
            String::from("127.0.0.1")
        } else {
            args[1].clone()
        };
31 32 33 34 35 36 37
        serv.push(':');
        serv.push_str(&args[2]);
        client::client(serv);
    } else {
        println!("Usage: {} [server ip] port", args[0]);
    }
}