std/net

March 13, 2026 ยท View on GitHub

The std/net module provides a comprehensive networking stack including TCP, UDP, DNS, and HTTP.

Usage

import "std/net/tcp.zc"  // TcpStream, TcpListener
import "std/net/udp.zc"  // UdpSocket
import "std/net/http.zc" // HTTP Client/Server
import "std/net/dns.zc"  // DNS Resolution
import "std/net/url.zc"  // URL Parsing
import "std/net/websocket.zc" // WebSocket

WebSocket (std/net/websocket.zc)

Type WebSocket

Provides server-side WebSocket handshake and framing.

MethodSignatureDescription
handshakeWebSocket::handshake(stream: TcpStream, key: String) -> Result<WebSocket>Performs the server-side handshake.
recvrecv(self) -> Result<String>Receives a text frame (handles unmasking).
sendsend(self, msg: String) -> Result<int>Sends a text frame.

HTTP Client & Server (std/net/http.zc)

Type Server

A simple multithreaded-capable HTTP server.

MethodSignatureDescription
newServer::new(port: int, handler: fn(Request*, Response*)) -> ServerCreates a new HTTP server.
startstart(self)Starts the server listening loop.

Client fetch

MethodSignatureDescription
fetchfetch(url: String) -> ResponsePerforms a GET request.

URL Parsing (std/net/url.zc)

Type Url

MethodSignatureDescription
parseUrl::parse(s: String) -> Option<Url>Parses a URL string.

TCP (std/net/tcp.zc)

Type TcpListener

MethodSignatureDescription
bindTcpListener::bind(host: char*, port: int) -> Result<TcpListener>Binds to a local address.
acceptaccept(self) -> Result<TcpStream>Accepts a new connection.

Type TcpStream

MethodSignatureDescription
connectTcpStream::connect(host: char*, port: int) -> Result<TcpStream>Connects to a remote host.
readread(self, buf: char*, len: usize) -> Result<usize>Reads from the stream.
writewrite(self, buf: u8*, len: usize) -> Result<usize>Writes to the stream.

UDP (std/net/udp.zc)

Type UdpSocket

MethodSignatureDescription
bindUdpSocket::bind(host: char*, port: int) -> Result<UdpSocket>Binds to a local address.
recv_fromrecv_from(self, buf: char*, len: usize) -> Result<UdpRecvResult>Receives data and sender info.
send_tosend_to(self, buf: char*, len: usize, host: char*, port: int) -> Result<usize>Sends data to a specific destination.

DNS (std/net/dns.zc)

Type Dns

MethodSignatureDescription
resolveDns::resolve(host: char*) -> Result<String>Resolves a hostname to an IP address.