std/network
The network: name resolution, TCP - a listener that accepts connections and a stream whose two directions are a
Source and a Sink of Bytes - and UDP, a socket that sends and receives datagrams. The IP addresses and socket
addresses it connects to are the values of std/ip, re-exported here, so a file that only names an address can
import them without claiming the network.
const server = TcpListener.listen(SocketAddress(IpAddress.loopback, 0))?
const client = TcpStream.connect(server.localAddress()).await()?
Everything that waits answers a Task and is cancellable; a timeout is within. Needs the network capability inside
a sandboxed script. See docs/design/NETWORK.md for the IO core under it; TLS is std/tls.
Modules
std/network/dnsDNS lookups: the stub resolver that asks a recursive name server for the records of a name (docs/design/DNS.md section 7).std/network/errorNetworkError: what every operation ofstd/networkfails with, one wrapper type, so a new kind of failure is never a breaking change (see "Algebraic Data Types and Pattern Matching" in CONCEPT.md).std/network/tcpTCP:TcpListeneraccepts connections,TcpStreamis one, andresolveturns a name into addresses.std/network/udpUDP: aUdpSocketsends and receives datagrams - each one whole, with the address it came from, or not at all (docs/design/NETWORK.md section 4, slice 5).
Everything
- fn
lookupThe records ofrecordTypethatnamehas, asked of the name servers the system is configured with:Resolver()'s [Resolver.lookup]. - type
NetworkErrorWhat went wrong on the network. - extend
NetworkError with From<AddressError>An address read from text that is none. - extend
NetworkError with From<DnsError>A name that is no domain name, where a lookup was asked for one:lookup(DomainName.tryFrom(text)?, ...). - fn
randomQueryIdentifierA random identifier for a DNS query, from the system's randomness (RFC 5452 section 9.2): what every transport of DNS draws for each question it sends, so that a forged answer has to guess it. - fn
resolveThe addresseshostnames: a literal address as it is,localhostas the two loopback addresses, and every other name through the system's resolver, in the order it answered. - type
ResolverHow [lookup] asks: which name servers, how long an attempt waits, and how many rounds over the servers it makes. - fn
systemNameServersThe name servers the system is configured with, in its order, on port 53: the servers of the network adapters that are up on Windows, thenameserverlines of/etc/resolv.confelsewhere. - type
TcpAcceptorWhat [TcpListener.acceptor] answers: the right to accept on a listening socket, as a value that moves between workers. - type
TcpListenerA socket that listens for connections. - type
TcpSinkThe writing direction of a [TcpStream]: aSink<Bytes, NetworkError>. - type
TcpSourceThe reading direction of a [TcpStream]: aSource<Bytes, NetworkError>. - type
TcpStreamOne TCP connection: bytes in both directions, in order, until either side ends its half. - type
UdpSocketA UDP socket: bound to a local address, and - once [UdpSocket.connect] named one - connected to one peer.