usocket:socket-connect
(usocket:socket-connect host port &key protocol element-type timeout deadline nodelay local-host local-port)
Opens a blocking TCP connection to host and port and returns a socket --
the usocket-compatible entry point over
rontolisp:tcp-connect. In this shim a socket IS
its stream handle, so usocket:socket-stream is the identity function and the
stream built-ins (read-line, write-line, write-string, read-byte,
write-byte, close) work on it directly.
Only TCP is supported: :protocol :datagram (UDP) signals an error. The other
keyword arguments are accepted for compatibility and ignored --
:element-type in particular, because a rontolisp socket handle is always
bidirectional and supports both the line and the byte built-ins (there is no
separate binary/character stream construction to select).
The cl-postgres (Postmodern) connection shape works verbatim:
(usocket:socket-stream
(usocket:socket-connect "localhost" 5432
:element-type '(unsigned-byte 8)))
A loopback echo round trip (single-threaded choreography: connect before accept, write before the peer reads):
The usocket package is loaded automatically on first use (interpreter) or
spliced into the compiled program (JVM / WASM component), and is also
registered as the built-in ASDF system "usocket", so
(asdf:load-system "usocket"), (ql:quickload :usocket) and a third-party
.asd's :depends-on ("usocket") all resolve to it without touching the
network. A connection failure signals a typed usocket:socket-error
condition (message preserved) on every backend that has sockets, so
(handler-case (usocket:socket-connect ...) (usocket:socket-error (e) ...))
works everywhere; the subtypes (usocket:connection-refused-error etc.) are
defined, but the re-signal always uses socket-error, so catch that. On the
WASM component backend the message reads tcp-connect: cannot connect to HOST:PORT, without the reason the host gave.
Backend support
- Interpreter and JVM: full support (delegates to
rontolisp:tcp-connect). - WASM: component mode only (
--component); a hostname resolves asrontolisp:tcp-connectresolves one there (run with-S allow-ip-name-lookup=y), and a failed connection signalsusocket:socket-error. A plain Preview 1.wasmsignals at the call. - Native executable (
--native): full support, as on the interpreter and the JVM -- a failed connection signalsusocket:socket-error(TCP sockets in a native executable). - Browser playground: not supported.