kex docs Standard Library 0.4.0-alpha kex.run ↗

Net

module Net

Shared networking values, capability discovery, and typed failures.

using Net

let https = Port.from(443).try
if Support.current.tls.usable? then https.string else "TLS unavailable" end

record Port

A validated TCP or UDP port number in 0..65535.

Use Port.from at input boundaries. Port zero requests an ephemeral port where a listening API permits it; after binding, ask the server or socket for the concrete port the operating system chose.

Fields

value
Integer

record SupportValue

Whether a feature was compiled into this backend and is usable now.

compiled? describes the build; usable? also accounts for the environment it is running in. A browser build may contain an HTTP client, for example, while browser policy still prevents a particular lower-level capability.

Fields

compiled?
Bool
usable?
Bool

record SupportReport

Granular networking capabilities for the current backend and environment.

Read this before choosing a transport dynamically. Applications that require one capability can instead check that single field during startup and fail with a useful message.

Fields

httpClient
SupportValue
httpServer
SupportValue
webSocketClient
SupportValue
webSocketServer
SupportValue

module Net.Port

Validated Port construction.

function from

Validates a port number.

from(value) : Integer -> Result<Port, NetError>
Parameters
value Integer
a number in 0..65535

Returns: Result<Port, NetError> — the validated port, or Parse

Examples

Reading a listen port from the environment

let number = ENV.get("PORT").flatMap { |text| text.to(Integer) }.or(8080)
let port = Port.from(number).try

module Net.Support

Runtime discovery for optional network transports and protocols.

constant current SupportReport

Reports compiled and currently usable networking features.

type NetOperation

The subsystem or operation that produced a networking error.

Variants

  • DNS
  • TCP
  • UDP
  • Unix
  • TLS
  • HTTPClient
  • HTTPServer
  • WebSocketClient
  • WebSocketServer

type NetErrorKind

Stable, backend-independent networking failure categories.

Variants

  • Parse
  • Resolve
  • Connect
  • Protocol
  • Timeout
  • Cancelled
  • Limit
  • Closed
  • ReadInProgress
  • UnsupportedBackend
  • UnsupportedOption
  • BrowserRestricted
  • OpaqueRedirect
  • MockEmpty
  • Backend

record NetError

A typed networking failure shared by every network module.

kind is the stable category to branch on. message is for a person, while phase adds protocol context such as a TLS handshake and progress records bytes transferred before a partial-operation failure. Keeping those roles separate lets programs recover without matching backend-specific prose.

Fields

operation
NetOperation
message
String
phase
String?
progress
Integer?

make Port

Submodules

  • Net.DNS Typed DNS lookup with explicit resolver ownership and bounded caching.
  • Net.HTTP Buffered HTTP clients, responses, and a small declaration-ordered server router. Requests never follow redirects or perform generic retries implicitly.
  • Net.HTTP.WebSocket High-level RFC 6455 client messages. The runtime handles fragmentation and ping/pong frames; reconnect and heartbeat policies remain application-owned.
  • Net.IP Validated, canonical IP addresses and CIDR networks.
  • Net.Socket Process-owned TCP byte streams and listeners. All blocking operations return typed NetError values; close operations are idempotent.