net

Transport-level (L4) networking: opening and accepting stream connections (TCP, Unix-stream, TLS), exchanging datagrams (UDP, Unix-datagram, DTLS), name resolution, and TLS upgrade or termination. The layer a database driver, custom binary protocol, WebSocket stack, or HTTP implementation is built on top of. Socket and resolver operations are impure and gated by the net capability under deny-by-default; parse-addr and addr-to-string are pure and capability-free. HTTP semantics live in cx-stdlib/http, not here.

net:parse-addr

[$net:parse-addr] -> element — Parse a restricted transport URL or bare host:port into an [addr] element; raises CXER4500 on a malformed URL.

            [?lib 'cx-stdlib/net']
[$net:parse-addr 'tcp://example.com:443']
          
            [addr host='example.com' port=443 family=ipv4]
          

net:addr-to-string

[$net:addr-to-string] -> string — Render an [addr] element to its canonical string form, round-tripping with parse-addr.

            [?lib 'cx-stdlib/net']
[$net:addr-to-string [$net:parse-addr 'tcp://example.com:443']]
          
            'example.com:443'
          

net:resolve

[$net:resolve] -> [sequence element] — Resolve a hostname to RFC 6724-ordered [addr]s; no record raises CXER4502, timeout CXER4503.

            [?lib 'cx-stdlib/net']
[$net:resolve 'example.com' {}]
          
            cx-err:CXER0271
          

net:dial

[$net:dial] -> element — Open a client connection, dispatching on the URL scheme (tcp/tls/udp/dtls/unix).

            [?lib 'cx-stdlib/net']
[$net:dial 'tcp://example.com:443' {}]
          
            cx-err:CXER0271
          

net:dial-tcp

[$net:dial-tcp] -> element — Open a TCP client connection; rejects a non-tcp scheme with CXER4501.

            [?lib 'cx-stdlib/net']
[$net:dial-tcp 'tcp://example.com:443' {}]
          
            cx-err:CXER0271
          

net:dial-tls

[$net:dial-tls] -> element — Open a TLS client connection, performing the handshake; server-name defaults to the dialed host.

            [?lib 'cx-stdlib/net']
[$net:dial-tls 'tls://example.com:443' {}]
          
            cx-err:CXER0271
          

net:dial-udp

[$net:dial-udp] -> element — Open a connected UDP datagram socket; rejects a non-udp scheme with CXER4501.

            [?lib 'cx-stdlib/net']
[$net:dial-udp 'udp://example.com:9000' {}]
          
            cx-err:CXER0271
          

net:dial-dtls

[$net:dial-dtls] -> element — Open a connected UDP socket and perform the client DTLS handshake, yielding a secure datagram socket.

            [?lib 'cx-stdlib/net']
[$net:dial-dtls 'dtls://example.com:8443' {}]
          
            cx-err:CXER0271
          

net:dial-unix

[$net:dial-unix] -> element — Connect to a Unix-domain stream socket by filesystem or abstract-namespace path.

            [?lib 'cx-stdlib/net']
[$net:dial-unix '/run/db.sock' {}]
          
            cx-err:CXER0271
          

net:listen

[$net:listen] -> element — Bind and listen for connections, dispatching on the URL scheme; a hostname binds all resolved addresses.

            [?lib 'cx-stdlib/net']
[$net:listen 'tcp://0.0.0.0:8080' {}]
          
            cx-err:CXER0271
          

net:listen-tcp

[$net:listen-tcp] -> element — Bind and listen for TCP connections; rejects a non-tcp scheme with CXER4501.

            [?lib 'cx-stdlib/net']
[$net:listen-tcp 'tcp://0.0.0.0:8080' {}]
          
            cx-err:CXER0271
          

net:listen-tls

[$net:listen-tls] -> element — Bind and listen for TLS connections; accept performs the server handshake using the stored config.

            [?lib 'cx-stdlib/net']
[$net:listen-tls 'tls://0.0.0.0:8443' {}]
          
            cx-err:CXER0271
          

net:listen-udp

[$net:listen-udp] -> element — Bind a UDP datagram socket; rejects a non-udp scheme with CXER4501.

            [?lib 'cx-stdlib/net']
[$net:listen-udp 'udp://0.0.0.0:9000' {}]
          
            cx-err:CXER0271
          

net:listen-dtls

[$net:listen-dtls] -> element — Bind a DTLS listener; accept runs the mandatory stateless cookie exchange plus server handshake.

            [?lib 'cx-stdlib/net']
[$net:listen-dtls 'dtls://0.0.0.0:8443' {}]
          
            cx-err:CXER0271
          

net:listen-unix

[$net:listen-unix] -> element — Bind a Unix-domain stream listener by filesystem or abstract-namespace path.

            [?lib 'cx-stdlib/net']
[$net:listen-unix '/run/srv.sock' {}]
          
            cx-err:CXER0271
          

net:accept

[$net:accept] -> element — Accept one incoming connection from a listener, performing any TLS/DTLS handshake.

            [?lib 'cx-stdlib/net']
[$net:accept [listener fd=6 transport='tcp' state='listening']]
          
            cx-err:CXER0271
          

net:accept-iter

[$net:accept-iter] -> [iterator element] — Iterate accepted connections, skipping transient per-client failures and stopping on listener-fatal errors.

            [?lib 'cx-stdlib/net']
[$net:accept-iter [listener fd=6 transport='tcp' state='listening']]
          
            cx-err:CXER0271
          

net:read-bytes

[$net:read-bytes] -> bytes — Read up to n bytes from a stream socket; n must be at least 1 else CXER4522.

            [?lib 'cx-stdlib/net']
[$net:read-bytes [socket fd=7 transport='tcp' state='open'] 4096]
          
            cx-err:CXER0271
          

net:read-exact

[$net:read-exact] -> bytes — Read exactly n bytes (a fixed frame); EOF before n raises CXER4509.

            [?lib 'cx-stdlib/net']
[$net:read-exact [socket fd=7 transport='tcp' state='open'] 16]
          
            cx-err:CXER0271
          

net:read-line

[$net:read-line] -> string — Read one UTF-8 line, stripping the trailing newline; invalid UTF-8 raises CXER4523.

            [?lib 'cx-stdlib/net']
[$net:read-line [socket fd=7 transport='tcp' state='open']]
          
            cx-err:CXER0271
          

net:read-all

[$net:read-all] -> string — Read the whole stream as UTF-8 text up to max-bytes (default 64 MiB); over raises CXER4510.

            [?lib 'cx-stdlib/net']
[$net:read-all [socket fd=7 transport='tcp' state='open'] {}]
          
            cx-err:CXER0271
          

net:read-all-bytes

[$net:read-all-bytes] -> bytes — Read the whole stream as raw bytes up to max-bytes (default 64 MiB); over raises CXER4510.

            [?lib 'cx-stdlib/net']
[$net:read-all-bytes [socket fd=7 transport='tcp' state='open'] {}]
          
            cx-err:CXER0271
          

net:write-bytes

[$net:write-bytes] -> null — Write the whole byte payload to a stream socket, all-or-raise with bytes-written observability.

            [?lib 'cx-stdlib/net']
[?lib 'cx-stdlib/bytes']
[$net:write-bytes [socket fd=7 transport='tcp' state='open'] [$bytes:from-string-utf8 'ping']]
          
            cx-err:CXER0271
          

net:write-string

[$net:write-string] -> null — Write a UTF-8 string to a stream socket, all-or-raise with bytes-written observability.

            [?lib 'cx-stdlib/net']
[$net:write-string [socket fd=7 transport='tcp' state='open'] 'hello']
          
            cx-err:CXER0271
          

net:write-line

[$net:write-line] -> null — Write a UTF-8 string followed by the socket's line terminator.

            [?lib 'cx-stdlib/net']
[$net:write-line [socket fd=7 transport='tcp' state='open'] 'GET / HTTP/1.0']
          
            cx-err:CXER0271
          

net:flush

[$net:flush] -> null — Flush any buffered outbound data on a stream socket.

            [?lib 'cx-stdlib/net']
[$net:flush [socket fd=7 transport='tcp' state='open']]
          
            cx-err:CXER0271
          

net:is-eof

[$net:is-eof] -> bool — Report whether the most recent read observed orderly end-of-stream; performs no I/O.

            [?lib 'cx-stdlib/net']
[$net:is-eof [socket fd=7 transport='tcp' state='open']]
          
            cx-err:CXER0271
          

net:line-iter

[$net:line-iter] -> [iterator string] — Iterate the stream as UTF-8 lines until end-of-stream.

            [?lib 'cx-stdlib/net']
[$net:line-iter [socket fd=7 transport='tcp' state='open']]
          
            cx-err:CXER0271
          

net:chunk-iter

[$net:chunk-iter] -> [iterator bytes] — Iterate the stream as fixed-size byte chunks until end-of-stream.

            [?lib 'cx-stdlib/net']
[$net:chunk-iter [socket fd=7 transport='tcp' state='open'] 4096]
          
            cx-err:CXER0271
          

net:send-to

[$net:send-to] -> int — Send one datagram to a target address (a gated effect point); returns the datagram length.

            [?lib 'cx-stdlib/net']
[$net:send-to [socket fd=9 transport='udp' state='bound'] 'ping' [addr host='10.0.0.5' port=9000 family='ipv4']]
          
            cx-err:CXER0271
          

net:recv-from

[$net:recv-from] -> element — Receive one datagram into an n-byte buffer, returning a [datagram] with bytes and sender address.

            [?lib 'cx-stdlib/net']
[$net:recv-from [socket fd=9 transport='udp' state='bound'] 2048]
          
            cx-err:CXER0271
          

net:send

[$net:send] -> int — Send one datagram on a connected socket; unconnected raises CXER4522.

            [?lib 'cx-stdlib/net']
[$net:send [socket fd=9 transport='udp' state='connected'] 'ping']
          
            cx-err:CXER0271
          

net:recv

[$net:recv] -> bytes — Receive one datagram on a connected socket into an n-byte buffer; oversize raises CXER4511.

            [?lib 'cx-stdlib/net']
[$net:recv [socket fd=9 transport='udp' state='connected'] 2048]
          
            cx-err:CXER0271
          

net:tls-wrap

[$net:tls-wrap] -> element — Perform a client TLS (or DTLS) handshake over an existing socket, consuming it for a secure one.

            [?lib 'cx-stdlib/net']
[$net:tls-wrap [socket fd=7 transport='tcp' state='open'] {server-name: 'example.com'}]
          
            cx-err:CXER0271
          

net:tls-accept

[$net:tls-accept] -> element — Perform a server TLS (or DTLS) handshake over an existing socket, consuming it for a secure one.

            [?lib 'cx-stdlib/net']
[$net:tls-accept [socket fd=7 transport='tcp' state='open'] {}]
          
            cx-err:CXER0271
          

net:peer-cert

[$net:peer-cert] -> element — Return the peer's certificate as a [cert] element, or the empty node-set if none.

            [?lib 'cx-stdlib/net']
[$net:peer-cert [socket fd=7 transport='tls' state='open']]
          
            cx-err:CXER0271
          

net:tls-info

[$net:tls-info] -> element — Return the negotiated TLS/DTLS version, cipher, and ALPN as a [tls] element.

            [?lib 'cx-stdlib/net']
[$net:tls-info [socket fd=7 transport='tls' state='open']]
          
            cx-err:CXER0271
          

net:close

[$net:close] -> null — Close a socket or listener (idempotent), cancelling and joining any in-flight operation.

            [?lib 'cx-stdlib/net']
[$net:close [socket fd=7 transport='tcp' state='open']]
          
            null
          

net:shutdown

[$net:shutdown] -> null — Half-close a stream in the read, write, or both direction (TLS sends close_notify).

            [?lib 'cx-stdlib/net']
[$net:shutdown [socket fd=7 transport='tcp' state='open'] 'write']
          
            cx-err:CXER0271
          

net:set-deadline

[$net:set-deadline] -> null — Set relative or absolute read/write deadlines on a socket; a lapsed deadline raises CXER4507.

            [?lib 'cx-stdlib/net']
[$net:set-deadline [socket fd=7 transport='tcp' state='open'] {both: 30}]
          
            cx-err:CXER0271
          

net:set-opt

[$net:set-opt] -> null — Set a per-transport socket option (nodelay, keepalive, line-terminator, etc.); unsupported raises CXER4521.

            [?lib 'cx-stdlib/net']
[$net:set-opt [socket fd=7 transport='tcp' state='open'] {nodelay: true}]
          
            cx-err:CXER0271
          

net:local-addr

[$net:local-addr] -> [sequence element] — Return the bound local address(es) as a sequence of [addr]; valid even after close (cached).

net:remote-addr

[$net:remote-addr] -> element — Return the peer address as an [addr], or the empty node-set if never connected; valid after close.

            [?lib 'cx-stdlib/net']
[$net:remote-addr [socket fd=999 transport='udp' state='bound']]
          
            ()
          

net:is-open

[$net:is-open] -> bool — Report whether a socket or listener handle is still open.

            [?lib 'cx-stdlib/net']
[$net:is-open [socket fd=999 transport='tcp' state='closed']]
          
            false