Here is the code
use std::net::UdpSocket;
fn main() {
let local_socket = UdpSocket::bind("127.0.0.1:2222").unwrap();
let mut buf = [0u8; 512];
loop {
println!("wait ... ");
match local_socket.recv_from(&mut buf){
Ok(_) => {
println!("Ok");
}
Err(_) => {
println!("Err");
}
}
}
}
Test the code with
dig @127.0.0.1 -p 2222 www.google.com
would works fine with output wait ...
before dig , but when I change println!("wait ... ");
to print!("wait ... ");
, It doesn't print anything until dig
happen. I don't know why does this happen?
The testing environment is rustc 1.0.0-nightly (93f7fe32d 2015-04-10) (built 2015-04-11)
on x86_64 GNU/Linux
Thank you