Sockets and the Socket API
Sockets are the BSD API for network communication. TCP flow: socket() → bind() → listen() → accept() (server) or socket() → connect() (client). After connection: read()/write() or send()/recv(). select() and poll() multiplex I/O across multiple fds without threads. epoll (Linux) and kqueue (BSD/macOS) are the scalable alternatives. Key gotcha: TCP is a byte stream, not a message stream — you must frame your own messages (length prefix or delimiter). htons()/ntohs() handle byte order.