class TcpListener
pub class TcpListener :: [Closeable]
Conforms to Closeable.
A listening TCP socket: bind creates it, accept returns each incoming connection as a
TcpStream.
Methods
pub static fn bind(addr: SocketAddr): TcpListener throws IoError
Returns a listener on addr; port 0 asks the system for a free one, which localAddr
reports. A port that a closed listener's connections still hold (TIME_WAIT) is taken all the
same.
Errors
Throws IoError with the address when the socket cannot be created, bound or set
listening, such as AddrInUse.
pub mut fn accept(): TcpStream throws [IoError, Cancelled]
Returns the next connection, waiting until one comes.
Errors
Throws IoError — Closed once the listener is closed —, and Cancelled when the waiting
task is cancelled.
pub fn localAddr(): SocketAddr throws IoError
Returns the address it listens on — with the port the system chose, where bind asked
for 0.
Errors
Throws IoError: Closed after close(), else the system's failure.
pub fn close(): void throws IoError
Closes the socket; a task that waits in accept throws Closed. A second close does
nothing.
Errors
Throws IoError when the system fails to close it.