Created
October 7, 2017 20:39
-
-
Save JFreegman/304920928edd66aa35d53192162a2647 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
let port = match get_available_port(DEAFULT_PORT_FROM, DEFAULT_PORT_TO) { | |
Some(port) => port, | |
None => panic!("failed to find available port"), | |
}; | |
let sockaddr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), port); | |
let new_sock = match UdpSocket::bind(&sockaddr) { | |
Ok(sock) => sock, | |
Err(e) => panic!("failed to bind socket to port {}; err={:?}", port, e), | |
}; | |
match new_sock.set_nonblocking(true) { | |
Ok(_) => (), | |
Err(e) => panic!("failed to set socket to non-blocking; err={:?}", e), | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment