Std\Net
Net – TCP and UDP networking with async I/O.
Provides TCP client/server sockets and UDP datagrams. Async operations
(tcpConnect, tcpAccept, send, recv, sendBytes, recvBytes)
use io_uring on Linux for non-blocking I/O.
Functions
Section titled “Functions”tcpConnect : String -> Int -> Int
Section titled “tcpConnect : String -> Int -> Int”Connect to a TCP server. Async (io_uring). Returns a socket descriptor.
import tcpConnect, send, recv, close from Std\Net inlet sock = tcpConnect "example.com" 80 indo send sock "GET / HTTP/1.0\r\nHost: example.com\r\n\r\n" let resp = recv sock 4096 in println resp close sockendtcpListen : String -> Int -> Int
Section titled “tcpListen : String -> Int -> Int”Create a TCP server socket bound to host:port. Returns a listener descriptor.
import tcpListen, tcpAccept, close from Std\Net inlet server = tcpListen "0.0.0.0" 8080 inlet client = tcpAccept server inclose clienttcpAccept : Int -> Int
Section titled “tcpAccept : Int -> Int”Accept an incoming TCP connection. Async (io_uring). Returns a client socket descriptor.
send : Int -> String -> Int
Section titled “send : Int -> String -> Int”Send a string over a socket. Async (io_uring). Returns the number of bytes sent.
recv : Int -> Int -> String
Section titled “recv : Int -> Int -> String”Receive up to maxBytes bytes from a socket as a string. Async (io_uring).
sendBytes : Int -> ByteArray -> Int
Section titled “sendBytes : Int -> ByteArray -> Int”Send a byte buffer over a socket. Async (io_uring). Returns the number of bytes sent.
recvBytes : Int -> Int -> ByteArray
Section titled “recvBytes : Int -> Int -> ByteArray”Receive up to maxBytes from a socket as a byte buffer. Async (io_uring).
close : Int -> Int
Section titled “close : Int -> Int”Close a socket descriptor. Returns 0 on success.
udpBind : String -> Int -> Int
Section titled “udpBind : String -> Int -> Int”Create a UDP socket bound to host:port. Returns a socket descriptor.
import udpBind, udpRecv, close from Std\Net inlet sock = udpBind "0.0.0.0" 9000 inlet msg = udpRecv sock 1024 inclose sockudpSendTo : Int -> String -> Int -> String -> Int
Section titled “udpSendTo : Int -> String -> Int -> String -> Int”Send a UDP datagram to host:port. Returns the number of bytes sent.
import udpBind, udpSendTo from Std\Net inlet sock = udpBind "0.0.0.0" 0 inudpSendTo sock "127.0.0.1" 9000 "hello"udpRecv : Int -> Int -> String
Section titled “udpRecv : Int -> Int -> String”Receive a UDP datagram of up to maxBytes. Returns the data as a string.
peerAddress : Int -> String
Section titled “peerAddress : Int -> String”Returns the remote address of a connected socket as a string.
import tcpConnect, peerAddress from Std\Net inlet sock = tcpConnect "example.com" 80 inpeerAddress sock # => "93.184.216.34"