data TcpListener
A listening TCP socket. Close it with close() (or let it go out of scope after close).
Example:
use std.net { SocketAddr, TcpListener }
fn main() -> () | NetError | ParseError io, net {
let l = TcpListener.bind(SocketAddr.parse("127.0.0.1:0")?)?
print("listening: {l.local.port > 0}")
l.close()?
}Output
listening: true
@must_close
pub(api) data TcpListenerThread safety. `accept` may be called by one task at a time; the accepted streams belong to the tasks that handle them.
Since. 1.0.0-beta
Fields
pub(api) local: SocketAddr | The address the socket listens on. |
Methods
bind | (addr: SocketAddr, backlog: i64) -> TcpListener | NetError netBinds and listens (SO_REUSEADDR is set). |
accept | (timeout: Duration?) -> TcpStream | NetError netWaits for the next connection. |
close | () -> () | NetError netCloses the listening socket. |
Defined in: std/net/net.oxl:348