Last active
October 18, 2016 09:10
-
-
Save tera3939/3980e3ac38179e1ceef4a7b2cb8206fe to your computer and use it in GitHub Desktop.
供養
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
[package] | |
name = "rust_de_tcpclient" | |
version = "0.1.0" | |
[dependencies] |
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
// TcpStream::connect()にaddr:Ipv4addrとport:u16を渡すために頑張ってたけど別に”localhost:8000”とかで渡しても大丈夫だった | |
use std::io::prelude::*; | |
use std::net::{self, Ipv4Addr, IpAddr, TcpStream}; | |
use std::env; | |
fn main() { | |
let args: Vec<String> = env::args().collect(); | |
match args.len() { | |
// 引数が無ければぺけちょんぱする | |
1 => panic!("hoge"), | |
// 引数が一つの場合, その引数をアドレスとする | |
2 => { | |
let ip_addr = match args[1].parse() { | |
Ok(ipv4addr) => ipv4addr, | |
Err(why) => panic!("{:?}", why), | |
}; | |
let port = 8000; | |
let tcp = TcpStream::connect(ip_addr, port); | |
}, | |
// 三つ目以降の引数は無視 | |
3 | _ => { | |
let ip_addr = match args[1].parse() { | |
Ok(ipv4addr) => ipv4addr, | |
Err(why) => panic!("{:?}", why), | |
}; | |
let port = match args[2].parse() { | |
Ok(port_number) => port_number, | |
Err(why) => panic!("{:?}", why), | |
}; | |
let tcp = TcpStream::connect(ip_addr, port); | |
}, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment