local_port
fn local_port(Stream s) -> Result<int, IoError> Import
Source: use io::net::udp::{local_port}; compiler/src/builtin_docs/io/net/udp.hy Returns the local port a UDP socket is bound to.
Useful after bind(host, 0) or connect to learn the port the OS
picked. Returns Err(IoError::AlreadyClosed) when s is not an open
UDP socket.
Parameters#
| Name | Type |
|---|---|
s | Stream |
Returns#
Result<int, IoError>
Examples#
use io::net::udp::{bind, local_port};
use tests::assert;
let sock = match bind("127.0.0.1", 0) {
Result::Ok(s) => s,
Result::Err(_) => panic "bind failed",
};
let port = match local_port(sock) {
Result::Ok(p) => p,
Result::Err(_) => 0,
};
assert!(port > 0 && port <= 65535);
See also#
io::net::udp::connectbind: Opens a UDP socket bound tohostandport.recv_from: Receives one datagram into the front ofbufwithout waiting.send_to: Sendsbufas one datagram tohostonportand returns how many bytes were sent.