Files, IO and the network

A program that only computes is rare. This part reads and writes files, opens a TCP socket and serves many clients on it, sends a datagram, talks HTTP, runs an external program through a port, and formats the output a person reads, all in Erlang with OTP alone.

The socket lessons use gen_tcp and gen_udp from the kernel application, and the HTTP lesson uses httpc from inets, both part of OTP. The commands run in the container and talk to the loopback address, so no lesson needs a network.

10.1 Files and IO file:read_file and write_file, the modes, and a directory walk Open 10.2 Sockets gen_tcp, a listening socket, accept, and the client that connects Open 10.3 HTTP clients httpc in inets, a request, the response tuple and the body Open 10.4 io:format and output the format directives, io_lib, and the difference from io:format Open 10.5 Ports and external programs os:cmd, a port, port_command, spawn_executable with arguments, the exit status, and what a port costs Open 10.6 File IO in depth a chunked read, pread and pwrite, the unicode encoding of a file, and the error of the wrong mode Open 10.7 A TCP server in depth the accept loop, a handler per client, controlling_process, and the active modes Open 10.8 UDP and inet gen_udp, the sender address, the active message, the inet functions, and the datagram that is lost Open

Lessons