(rontolisp) docs
← rontolisp Package Functions

rontolisp:tcp-local-address rontolisp:tcp-peer-address rontolisp:tcp-peer-port

(rontolisp:tcp-local-address handle) -- (rontolisp:tcp-peer-address handle) -- (rontolisp:tcp-peer-port handle)

Address introspection for TCP handles. tcp-local-address returns the local (bound) IP address of a listener or socket handle as a string; tcp-peer-address and tcp-peer-port return the remote IP address (a string) and remote port (an integer) of a connected socket handle. Together with rontolisp:tcp-local-port they back the usocket:get-local-* / usocket:get-peer-* accessors of the usocket shim.

The peer accessors reject a listener handle (a listener has no peer):

$ rontolisp
CL-USER> (setq l (rontolisp:tcp-listen 0 "127.0.0.1"))
CL-USER> (rontolisp:tcp-peer-address l)
Error: TCP-PEER-ADDRESS expects a connected socket handle

Backend support

  • Interpreter and JVM: getLocalAddress() / getInetAddress() / getPort() on the underlying java.net.Socket / ServerSocket. A value that is not an open handle of the right kind (a listener, a closed socket, a file stream, 1, nil) signals the simple-error above on both.
  • WASM: component mode only -- all three return real addresses and ports, exactly like the interpreter/JVM. On failure or a wrong kind of handle they return nil instead of signaling (so a spliced usocket program still runs there). Call-time error in Preview 1 (core-module) mode, like every tcp built-in.
  • Native executable (--native): as on the interpreter and the JVM -- real addresses and ports, and the simple-error above for a wrong kind of handle (TCP sockets in a native executable).
  • Browser playground: not supported.