pub struct TcpListener { /* private fields */ }Expand description
Listening endpoint for inbound TCP connections.
Holding this alive keeps the bound socket open; dropping it closes the socket (the OS releases the port).
Implementations§
Source§impl TcpListener
impl TcpListener
Sourcepub fn bind(scheme: &str, host: &str, port: u16) -> Result<Self>
pub fn bind(scheme: &str, host: &str, port: u16) -> Result<Self>
Bind a new listener at host:port, honoring the address-family
hint tcp4 / tcp6 / tcp encoded in scheme. Passing port
0 requests an ephemeral port from the OS; the caller can read
the assigned port back via local_addr.
Sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
The locally-bound socket address. Useful for reading back the
OS-assigned ephemeral port after binding with port 0.
Trait Implementations§
Source§impl Drop for TcpListener
impl Drop for TcpListener
Auto Trait Implementations§
impl Freeze for TcpListener
impl RefUnwindSafe for TcpListener
impl Send for TcpListener
impl Sync for TcpListener
impl Unpin for TcpListener
impl UnsafeUnpin for TcpListener
impl UnwindSafe for TcpListener
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more