Unit content
Network sockets and endpoint lifecycle
A network socket is an operating-system interface through which a process uses a transport protocol.
For a connection-oriented server, the typical lifecycle is:
socket → bind → listen → accept → read/write → close
bind associates a local address and port with the listening socket. listen marks it as accepting incoming connections. accept produces a new connected socket for one client while the listening socket remains available for further clients.
A client typically creates a socket and calls connect, after which both sides exchange bytes through the connected endpoint.
Datagram sockets use the same endpoint idea without establishing a TCP-style connection for every peer.
The socket API is not the network protocol itself. It is the local programming abstraction by which applications ask the kernel's networking stack to send and receive protocol data.