Skip to content

Functions Network

Paul Squires edited this page Oct 26, 2026 · 3 revisions

Home › Function Finder › Networking

Networking

The functions to look up hosts, connect over TCP and UDP, parse and build URLs, fetch web pages over HTTP and HTTPS, grouped by what you want to do. The From column says what a program needs before it can call one:

  • std/<Name>: #import "std/<Name>", then using <Name> to call it by its bare name.

Jump to: Parse, print and classify IP addresses · Look up a host name · Connect to a TCP server · Read and write a TCP connection · Accept TCP connections · Send and receive UDP datagrams · Take a URL apart and build one · Read and build query strings · Find out why a network call failed · Fetch a web page or call a web API · Read a large download as it arrives · Encrypt a connection with TLS · Find out why an HTTP request or TLS handshake failed

Parse, print and classify IP addresses

Function What it does From
ParseIp Parses IPv4 or IPv6 text, with an optional zone, and refuses leading zeros. std/net
IpAddress Holds one IPv4 or IPv6 address as a value that can be copied and compared. std/net
IpAddress.ToString Returns the address as text, IPv6 in its shortest lower-case form. std/net
IpAddress.IsLoopback / IsPrivate / IsLinkLocal Tells whether the address is loopback, private or link-local. std/net
IpAddress.IsMulticast / IsUnspecified / IsGlobalUnicast Tells whether the address is multicast, all zeros or an ordinary unicast address. std/net
IpAddress.IsV4Mapped / Unmap Recognises an IPv4 address written as IPv6 and turns it back into IPv4. std/net
Ipv4 Returns the IPv4 address made of four numbers. std/net
IpFromBytes Returns the address held in 4 or 16 bytes. std/net
Loopback Returns 127.0.0.1, or ::1 when asked for IPv6. std/net
AnyAddress Returns 0.0.0.0 or ::, the address that binds every interface. std/net
SocketAddress Holds an IP address and a port, printed as 1.2.3.4:80 or [::1]:80. std/net
ParseSocketAddress Parses an address and port, with brackets around IPv6. std/net

Look up a host name

Function What it does From
Resolve Looks up a host name and returns every address it has, each with the given port. std/net

Connect to a TCP server

Function What it does From
TcpStream Holds one TCP connection, which reads and writes like any stream. std/net
TcpStream.Connect Connects to an address and port, giving up after an optional timeout. std/net
TcpStream.ConnectHost Looks up a host and connects to the first of its addresses that answers. std/net

Read and write a TCP connection

Function What it does From
TcpStream.SetReadTimeout / SetWriteTimeout Makes a read or write that waits too long fail with a timeout. std/net
TcpStream.SetNoDelay Sends small writes at once instead of gathering them. std/net
TcpStream.SetKeepAlive Probes an idle connection so that a dead peer is noticed. std/net
TcpStream.Shutdown Tells the peer no more data is coming, so its reads end. std/net
TcpStream.LocalAddress / PeerAddress Returns the address and port of this end or of the other end. std/net
TcpStream.Close Closes the connection; closing twice is harmless. std/net

Accept TCP connections

Function What it does From
TcpListener Holds a listening socket that waits for TCP connections. std/net
TcpListener.Bind Binds an address and port and starts listening; port 0 picks a free one. std/net
TcpListener.Accept Waits for the next connection and opens a TcpStream on it, with an optional timeout. std/net
TcpListener.LocalAddress Returns the address and port the listener is bound to. std/net

Send and receive UDP datagrams

Function What it does From
UdpSocket Holds a socket that sends and receives single datagrams. std/net
UdpSocket.Bind Receives datagrams on an address and port. std/net
UdpSocket.SendTo / ReceiveFrom Sends a datagram to an address, or waits for one and reports its sender. std/net
UdpSocket.Connect / Send / Receive Fixes the other end, then sends and receives without naming it. std/net
UdpSocket.SetReadTimeout Makes a receive that waits too long fail with a timeout. std/net
UdpSocket.SetBroadcast / JoinMulticast Allows broadcast sends, or receives a multicast group. std/net

Take a URL apart and build one

Function What it does From
ParseUrl Takes a URL apart into scheme, user, host, port, decoded path, query and fragment. std/net
Url Holds a URL as fields that can be read, changed and printed again. std/net
Url.ToString Returns the URL as text, escaping each part only as much as it needs. std/net
Url.Resolve Makes a relative link absolute against this URL, removing . and .. segments. std/net
Url.HostPort / EscapedPath Returns host:port, or the path as it appears in the URL. std/net

Read and build query strings

Function What it does From
Url.Query Returns the URL's query string parsed into QueryValues. std/net
ParseQuery Parses name=value pairs, decoding percent escapes and plus signs. std/net
QueryValues Holds query pairs in order, where one name may appear more than once. std/net
QueryValues.Get / GetAll Returns the first value of a name, or every value of it. std/net
QueryValues.Add / SetValue / Remove Appends a pair, replaces a name's values, or removes a name. std/net
QueryValues.Encode Returns the pairs as query text in order, with spaces as plus signs. std/net

Find out why a network call failed

Function What it does From
NetError Holds why a network call failed: a code, the system's number and a message. std/net
NetErrorMessage Returns the fixed English text for a NetErrorCode. std/net

Fetch a web page or call a web API

Function What it does From
Fetch Fetches a URL with GET on a fresh client and returns the whole response. std/http
Post Posts a text body to a URL on a fresh client and returns the whole response. std/http
Client Holds the request settings and reuses connections to the same host. std/http
Client.Fetch Fetches a URL with GET and returns the whole response. std/http
Client.Head Sends a HEAD request and returns the status and headers. std/http
Client.Post Posts a text body with its content type and returns the whole response. std/http
Client.Send Sends a Request, follows redirects and reads the whole body into a Response. std/http
Request Holds a method, URL, headers and body to send. std/http
Request.SetBody Sets the body as UTF-8 text and its Content-Type. std/http
Request.SetBasicAuth Adds an Authorization: Basic header for a user name and password. std/http
Response Holds the status, headers, final URL and body of a reply. std/http
Response.Text Returns the body decoded as UTF-8 text. std/http
Headers Holds header fields in order, with names compared regardless of case. std/http

Read a large download as it arrives

Function What it does From
Client.Open Sends a request and hands the body over as a stream to read at your own pace. std/http
ResponseStream Reads a response body as a stream and gives the connection back when closed. std/http

Encrypt a connection with TLS

Function What it does From
TlsStream Encrypts a connected stream with TLS, as a client or a server. std/tls
TlsStream.ConnectHost Opens a TCP connection to a host and shakes hands as a TLS client. std/tls
TlsStream.Connect Shakes hands as a TLS client over a stream that is already connected. std/tls
TlsStream.Accept Shakes hands as a TLS server over an accepted connection. std/tls
TlsConfig Holds the TLS version floor, extra trusted roots and a server's certificate and key. std/tls
TlsConfig.AddRootPem Trusts the root certificates in PEM text as well as the system's. std/tls
TlsConfig.SetIdentityPem Sets a server's certificate chain and PKCS#8 private key from PEM text. std/tls

Find out why an HTTP request or TLS handshake failed

Function What it does From
HttpError Holds why an HTTP request failed: a code, the URL and the lower layer's message. std/http
TlsError Holds why a TLS handshake failed, such as an untrusted or expired certificate. std/tls

See Also


Home · Function Finder · Keyword Index

Clone this wiki locally