TcpListenerThe server side of TCP: a socket bound to a local address, accepting incoming connections.
listen:'host:port' binds (port 0 picks an ephemeral port — read it back with port); then accept / acceptOnce: / acceptLoop: yield each incoming connection as a TcpSocket. Accepting parks the task, so one program can serve many listeners and connections concurrently.
var srv = TcpListener.listen:'127.0.0.1:0' srv.port "* e.g. 50121 -- the ephemeral port the OS chose srv.acceptLoop:{ |sock| sock.writeAll:'hi\n'.asBytes }
Bind a listening socket to 'host:port' — '127.0.0.1:8080' for local-only, '0.0.0.0:8080' for every interface, port 0 for an ephemeral port (read the chosen one back with port). A bind failure (port in use, privileged port) throws a catchable IoError.
Wait (parking the task) until a peer connects, answering the connected TcpSocket. The caller owns it: close it when done, or prefer acceptOnce: / acceptLoop:, which close it for you.
Accept connections forever, running the block on each; every socket is closed after its block, on every exit path. The loop ends only by a non-local return (^^), a throw, or task cancellation propagating out of the block — the classic serve-forever shape.
Accept one connection, run the block with it, and close it on every exit path (normal, throw, or cancel); answers the block's value.
Stop listening and close the socket (idempotent); further accepts throw. Already-accepted connections live on independently. Returns nil.
Whether the listener has been closed.
The actually-bound local port (Integer) — how you learn the port after an ephemeral :0 bind.