Struct axstd::net::TcpListener
source · pub struct TcpListener(/* private fields */);net only.Expand description
A TCP socket server, listening for connections.
Implementations§
source§impl TcpListener
impl TcpListener
sourcepub fn bind<A: ToSocketAddrs>(addr: A) -> Result<TcpListener>
pub fn bind<A: ToSocketAddrs>(addr: A) -> Result<TcpListener>
Creates a new TcpListener which will be bound to the specified
address.
The returned listener is ready for accepting connections.
Binding with a port number of 0 will request that the OS assigns a port
to this listener. The port allocated can be queried via the
TcpListener::local_addr method.
The address type can be any implementor of ToSocketAddrs trait. See
its documentation for concrete examples.
If addr yields multiple addresses, bind will be attempted with
each of the addresses until one succeeds and returns the listener. If
none of the addresses succeed in creating a listener, the error returned
from the last attempt (the last address) is returned.
sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
Returns the local socket address of this listener.