lev.listen

lev

listen(addr, port, opts) -> listener, err

Create a bound listening TCP socket

Creates and binds a TCP listener socket. Returns a listener object with an accept method that yields until a client connects. accept takes a timeout (number) or an options table { timeout = N, cancel = token }.

Port 0 binds a port the kernel picks. The listener's getsockname returns the bound addr, port, so a caller reads the pick back with no probe for a free port, and no race for it. A port outside 0..65535 answers nil, "invalid port".

Options: