rontolisp:tcp-listen
(rontolisp:tcp-listen port &optional host)
Binds a listening TCP socket on port and returns a listener handle for
rontolisp:tcp-accept and close.
Port 0 picks a free ephemeral port — read the actual port back with
rontolisp:tcp-local-port. Without host the
listener binds all interfaces; pass an address string (for example
"127.0.0.1") to bind only one.
A server accepts connections in a loop; each accepted handle is a
bidirectional stream (see
rontolisp:tcp-accept):
(let ((listener (rontolisp:tcp-listen 7777)))
(do ((n 1 (+ n 1))) (nil)
(let ((sock (rontolisp:tcp-accept listener)))
(do ((line (read-line sock) (read-line sock)))
((null line) (close sock))
(write-line line sock))))) ; echo every client forever
Backend support
- Interpreter and JVM: use the JDK
java.net.ServerSocket(withSO_REUSEADDRon the interpreter); a failed bind (for example a port already in use) signals an error. - WASM: component-only, over
wasi:sockets@0.3.0.hostmust be an IPv4 literal. Compile with--componentand run with-S tcp=y -S inherit-network=yon top of the async flags; a failed bind returnsnil. Compile error in Preview 1 (core-module) mode. - Browser playground: not supported (no raw TCP in the browser sandbox).
Limitations
- The listener handle only supports
rontolisp:tcp-accept,rontolisp:tcp-local-portandclose— it is not a byte stream itself. - See
rontolisp:tcp-connectfor the shared socket limitations (TCP only, IPv4 literals on WASM). The listener serves plain TCP; for a TLS listener userontolisp:tls-listen(interpreter/JVM only).