Skip to content

Sockets Domain

The Sockets domain exposes low-level TCP/UDP sockets for custom protocols and long-lived connections.

aivi
use aivi.net.sockets

Types

aivi
type Address = { host: Text, port: Int }
type SocketError = { message: Text }

TCP

FunctionExplanation
listen address
Address -> Resource Listener
Creates a TCP listener bound to address.
accept listener
Listener -> Effect SocketError Connection
Waits for and returns an incoming TCP connection.
connect address
Address -> Effect SocketError Connection
Opens a TCP connection to address.
send connection bytes
Connection -> List Int -> Effect SocketError Unit
Sends raw bytes to the remote endpoint.
recv connection
Connection -> Effect SocketError (List Int)
Receives raw bytes from the remote endpoint.
close connection
Connection -> Effect SocketError Unit
Closes the TCP connection.