For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).
net
Provides networking: IP and socket addresses, and TCP sockets.
Examples:
from std.net import SocketAddrV4
from std.net.blocking import TCPListener, TCPStream
def main() raises:
var listener = TCPListener(bind=.v4(SocketAddrV4(.localhost, 0)))
var client = TCPStream(connect=listener.local_addr())
var server, _ = listener.accept()
client.write_all("ping".as_bytes())
var buffer = List[Byte](length=4, fill=0)
var n = server.read(buffer)
Packages
-
blocking: Provides sockets whose operations block the calling thread until they finish. -
tcp: Provides what TCP sockets share whether or not they block, such as the options instd.net.tcp.option.