A socket is an endpoint for communication between processes. Unix sockets come in several families: AF_INET (IPv4 network sockets, identified by IP address and port), AF_INET6 (IPv6), and AF_UNIX (local inter-process sockets identified by a filesystem path). Linux also supports more exotic families like AF_NETLINK (talking to the kernel), AF_PACKET (raw layer-2 packets), and AF_VSOCK (virtualisation).
The socket API is one of the oldest and most widely used programming interfaces in computing, introduced in 4.2BSD in 1983 and now part of POSIX. The basic calls are socket, bind, listen, accept, connect, send, recv, and close. They work the same whether the socket is TCP/IP on the other side of the world or a Unix socket in /run/.
Unix domain sockets deserve special mention. They are used for fast local IPC without network overhead: X11 uses /tmp/.X11-unix/, D-Bus uses /run/dbus/, PostgreSQL uses /var/run/postgresql/.s.PGSQL.5432, Docker uses /var/run/docker.sock. They support file-system permissions as access control, which is sometimes exactly what you want.
Discussed in:
- Chapter 12: Networking — IP Addresses, Ports, and Sockets
Also defined in: Textbook of Linux