i got send/recv mixed up
This commit is contained in:
parent
078c026858
commit
03eff314a7
|
@ -1,41 +1,5 @@
|
||||||
use std::str::FromStr;
|
|
||||||
|
|
||||||
extern crate hptp;
|
extern crate hptp;
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
struct Hostname {
|
|
||||||
ip: String,
|
|
||||||
port: u16,
|
|
||||||
}
|
|
||||||
|
|
||||||
struct InvalidHostnameError;
|
|
||||||
|
|
||||||
impl FromStr for Hostname {
|
|
||||||
type Err = InvalidHostnameError;
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
||||||
let i = s.find(':').ok_or(InvalidHostnameError)?;
|
|
||||||
Ok(Hostname {
|
|
||||||
ip: s[..i].into(),
|
|
||||||
port: s[i + 1..].parse().map_err(|_| InvalidHostnameError)?,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn usage() {
|
|
||||||
print!("usage:\n./3700recv <host-ip>:<host-port>\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn parse_args() -> Result<Hostname, ()> {
|
|
||||||
std::env::args().nth(1).ok_or(())?.parse().map_err(|_| ())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
match parse_args() {
|
println!("{}", hptp::RECV_GREETING);
|
||||||
Ok(x) => start(x),
|
|
||||||
Err(_) => usage(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn start(hn: Hostname) {
|
|
||||||
println!("ip={}, port={}", hn.ip, hn.port)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,41 @@
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
extern crate hptp;
|
extern crate hptp;
|
||||||
|
|
||||||
fn main() {
|
#[derive(Debug)]
|
||||||
println!("{}", hptp::SEND_GREETING);
|
struct Hostname {
|
||||||
|
ip: String,
|
||||||
|
port: u16,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct InvalidHostnameError;
|
||||||
|
|
||||||
|
impl FromStr for Hostname {
|
||||||
|
type Err = InvalidHostnameError;
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
let i = s.find(':').ok_or(InvalidHostnameError)?;
|
||||||
|
Ok(Hostname {
|
||||||
|
ip: s[..i].into(),
|
||||||
|
port: s[i + 1..].parse().map_err(|_| InvalidHostnameError)?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn usage() {
|
||||||
|
print!("usage:\n./3700send <host-ip>:<host-port>\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_args() -> Result<Hostname, ()> {
|
||||||
|
std::env::args().nth(1).ok_or(())?.parse().map_err(|_| ())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
match parse_args() {
|
||||||
|
Ok(x) => start(x),
|
||||||
|
Err(_) => usage(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn start(hn: Hostname) {
|
||||||
|
println!("ip={}, port={}", hn.ip, hn.port)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue