Applications need a way to access network services (TCP, UDP) without implementing protocol internals. An interface is needed to allow applications to send/receive data over the network.
An application programming interface that provides a set of functions for applications to use network services, acting as the Service Access Point between the application and transport layers.
- Application calls
socket()to create a socket endpoint - Calls
bind()to assign local address/port (server) orconnect()to initiate connection (client) - Uses
send()/recv()(orwrite()/read()) to exchange data - Calls
close()to terminate the connection - Server uses
listen()andaccept()to handle incoming connections
- Standardized interface across operating systems (Berkeley sockets, Winsock)
- Hides protocol details from applications
- Supports both connection-oriented (TCP) and connectionless (UDP) sockets
- File descriptor-based (sockets behave like files)
- Built from: Service Access Point — concrete implementation of SAP
- Built from: Service Primitives — API calls are primitives
- Related: TCP and UDP — accessed via socket API
- Related: Application Layer — applications use sockets
- Blocking vs non-blocking sockets: blocking waits, non-blocking returns immediately
- Socket descriptor leaks if
close()isn’t called (resource exhaustion) - Different socket types: stream (TCP), datagram (UDP), raw sockets