Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

net

import net

The net module provides networking primitives for Transmission Control Protocol and User Datagram Protocol communication as well as IP address manipulation interfaces.

  • TcpStream communicates over TCP.
  • UdpSocket communicates over UDP.
  • UnixStream communicates over a unix domain socket, which is a path on the filesystem rather than an address on the network.
  • Ip parses, formats and classifies IP addresses.
  • SocketAddr pairs an IP address with a port.
  • net.tls wraps a TcpStream in Transport Layer Security.
  • net.dtls provides Datagram Transport Layer Security over UDP.
  • net.poll waits on many sockets at once.
  • net.resolver asks the domain name system questions of its own.

The net API

Every public name in net, wherever it is declared. Each links to the page that documents it.

NameKindSummary
net.AcceptorclassAn accept loop that never parks the thread inside accept().
net.ERRORconstantReadiness only: the socket has failed, or its handle can no longer supply a descriptor because it was closed,…
net.HANGUPconstantReadiness only: the peer has closed its end.
net.IpclassEither an Ipv4 or an Ipv6, for code that needs to accept and work with addresses of either family without…
net.Ipv4classAn IPv4 address, stored internally as four octets in network (i.e. big-endian, most significant octet first)…
net.Ipv6classAn IPv6 address, stored internally as eight 16-bit segments in network (i.e. big-endian, most significant…
net.PollerclassA set of sockets to watch, each under a token of your choosing.
net.READABLEconstantInterest: tell me when this socket has data to read, a connection to accept, or an end-of-stream to observe.
net.ShutdownclassUsed with TcpStream.shutdown() to select which half (or both halves) of a full-duplex TCP connection to…
net.SocketAddrclassEither a SocketAddrV4 or a SocketAddrV6, for code that needs to accept and work with socket addresses of…
net.SocketAddrV4classAn IPv4 address and port, e.g. 192.168.1.10:8080.
net.SocketAddrV6classAn IPv6 address and port, e.g. [2001:db8::1]:8080, optionally carrying a zone/scope identifier (RFC 4007)…
net.TcpStreamclassA TCP socket, in either its connected-stream or listening-server role.
net.UdpSocketclassA UDP socket, usable for both sending and receiving datagrams, either to/from a single fixed peer (after…
net.UnixStreamclassA unix domain socket, connected or listening.
net.WRITABLEconstantInterest: tell me when this socket can be written to without blocking.
net.dtls.DtlsConfigclassThe trust roots and optional certificate a DTLS handshake needs - the same idea as tls.TlsConfig, minus the…
net.dtls.DtlsSocketclassA DTLS socket, in either its connected (client or accepted-server) role or its listening role.
net.is_supportedfunctionWhether unix domain sockets work on this machine.
net.pairfunctionTwo sockets already connected to each other, with no path and nothing on the filesystem.
net.resolvefunctionResolves address - a host:port string whose host may be a name or an IP literal - into every socket…
net.resolver.CLASSESconstantThe classes a question can be asked in.
net.resolver.CertificationclassA CAA record: which certificate authorities a domain allows to issue for it.
net.resolver.MailExchangeclassOne mail server for a domain, as an MX record names it.
net.resolver.MalformedResponseclassSomething came back that is not a DNS message, or is one that contradicts itself.
net.resolver.NameErrorclassThe name does not exist.
net.resolver.NoServersErrorclassThe resolver has nowhere to send a query: no servers were given and the system has none configured.
net.resolver.QuestionclassThe question a message asks, echoed back in the answer so a reply can be matched to what it replies to.
net.resolver.RCODESconstantWhat a server said about the question, by name.
net.resolver.RecordclassOne resource record: a name, what kind of thing it holds, how long it may be cached, and the thing itself.
net.resolver.ResolverclassAsks questions of the domain name system and reads the answers.
net.resolver.ResolverErrorclassThe root of every error this module raises.
net.resolver.ResolverTimeoutclassNo server answered in time.
net.resolver.ResponseclassA whole answer: what was asked, what came back, and what the server said about it.
net.resolver.ServerErrorclassThe server answered, and the answer was a refusal or a failure of its own.
net.resolver.ServiceclassWhere a service lives, as an SRV record names it: the host and port, with the priority and weight that…
net.resolver.StartOfAuthorityclassThe authority record at the top of a zone, which says who publishes it and how long the rest of the world may…
net.resolver.TYPESconstantThe record types this module knows how to read, by name.
net.resolver.afunctionThe IPv4 addresses of a name.
net.resolver.aaaafunctionThe IPv6 addresses of a name.
net.resolver.addressesfunctionEvery address a name has, IPv4 first.
net.resolver.build_queryfunctionBuilds the bytes of a query.
net.resolver.caafunctionWhich certificate authorities a domain allows to issue for it.
net.resolver.cnamefunctionThe name this one is an alias for, or nil.
net.resolver.exchangefunctionAsks one server one question and returns what it said.
net.resolver.flushfunctionEmpties the shared resolver’s cache.
net.resolver.mxfunctionThe mail servers for a domain, lowest preference first.
net.resolver.nsfunctionThe nameservers a domain is delegated to.
net.resolver.parse_messagefunctionTurns the bytes of a message into a Response.
net.resolver.ptrfunctionThe names an address points back at.
net.resolver.queryfunctionAsks the shared resolver about one name and hands back the whole answer.
net.resolver.resolvefunctionThe records of one type published for a name, through the shared resolver.
net.resolver.reverse_namefunctionThe name an address’s records are published under.
net.resolver.sharedfunctionThe resolver the module-level functions use: one shared Resolver built from this machine’s own…
net.resolver.soafunctionThe authority record at the top of a name’s zone, or nil.
net.resolver.srvfunctionThe hosts running a service, by priority and then by weight.
net.resolver.system_searchfunctionThe domain suffixes to try against a name that has no dots in it.
net.resolver.system_serversfunctionThe nameservers this machine is configured to use, in the order the system lists them.
net.resolver.txtfunctionThe text records of a name.
net.resolver.usefunctionReplaces the shared resolver, so that every module-level function goes through the one given instead.
net.tls.PeerCertificateclassThe subset of a peer’s certificate that’s useful to inspect from Zuri code, without needing a full…
net.tls.TlsConfigclassThe handful of choices a TLS handshake needs: which certificate authorities to trust, an optional certificate…
net.tls.TlsStreamclassAn established TLS connection, wrapping an already-connected TcpStream.

Submodules

ModuleReached asSummary
net.addrnet.*Socket addresses: an IP address and a port.
net.dtlsnet.dtls.*Datagram Transport Layer Security over a UdpSocket - the same certificate-based encryption and…
net.ipnet.*This module provides types for parsing, formatting, comparing and classifying IP addresses in both their IPv4…
net.pollnet.*Readiness polling: given a set of sockets, which of them can be read or written right now, without blocking.
net.resolvernet.resolver.*A DNS resolver, written in Zuri from the wire format up.
net.tcpnet.*This module provides a complete implementation of the Transmission Control Protocol as specified in IETF RFC…
net.tlsnet.tls.*Transport Layer Security over a TcpStream, built on top of rustls.
net.udpnet.*This module provides a complete implementation of the User Datagram Protocol as specified in IETF RFC 768.
net.unixnet.*Unix domain sockets: the same stream interface as tcp, over a path on the filesystem rather than an address…

2026, Richard Ore and Zuri contributors