std.net — Overview

std.net is the networking surface. Every object is event-driven: you install on_* callbacks and the engine invokes them on background tasks when data arrives. The calling script must stay alive (std.async.sleep / await) or the callbacks never fire.

TLS

TCP, UDP, HTTP, and WebSocket transmit in plaintext by default. TLS is
available when the engine is built with OpenSSL
— tcp_client.connect(..., {tls: true}),
tcp_server.listen(..., {cert, key}), http_server.listen(..., {cert, key}),
https:// request URLs, and wss:// websockets all work on OpenSSL builds.
Without OpenSSL they throw UNSUPPORTED (see Errors).

Mental model

  1. Create an object: std.net.tcp_server(), udp(), http_client(), etc.
  2. Install handlers with on_connect, on_receive, on_message, …
  3. Start it: listen, connect, bind, or request.
  4. Keep the script alive — e.g. std.async.sleep(5000) — so background fibers can run.
  5. Stop/close when done: stop(), close().

All network work runs through the same fiber pool as std.async and std.time timers — failures in connection-oriented callbacks (TLS handshake, background errors) are recorded on the owning object and polled via last_error() (tcp_client, tcp_server, udp, websocket, http_server — see Concurrency — Errors).

Modules

Page What it covers
TCP tcp_client / tcp_server — message-based, on_connect/on_receive/on_disconnect
UDP udp — connectionless bind + send_to
HTTP Client http_client — single request with headers and http_codes
HTTP Server http_server — routes + handlers returning string or response object
WebSocket websocket — text/binary frames, on_message/on_close
URL parse_url plus the url sub-module — parse, build, percent/form encode
DNS dns_lookup — hostname → IP array
HTTP Codes http_codes — named status constants (.ok, .not_found, …)

Each page is self-contained with runnable examples and a method table. Start with TCP for the core event-driven pattern, then pick the protocol you need. See Concurrency for sleep/await that keeps these servers alive.