Socket
A socket is a network communication endpoint identified by (protocol, local IP, local port, remote IP, remote port), serving as the interface between the application and transport layers.
Purpose
It gives applications an abstract communication endpoint that hides the underlying protocol details.
Mechanism
The socket API: socket() creates, bind() assigns an address, listen() puts a server in listening mode, accept() takes a connection, connect() dials from the client, send()/recv() transfer data, and close() shuts down. TCP sockets have a state machine; UDP is connectionless.
Use cases
- Network servers and clients
- Database connections
- WebSocket communication
- Unix domain sockets (local IPC)
Examples
- Input
(TCP, 0.0.0.0:8080, client:1234)OutputOne connected TCP socketThe five-tuple
Common errors
- Unclosed sockets exhaust available ports
- Use SO_REUSEADDR or close sockets promptly
Related terms
Port
A port is a transport-layer 16-bit address (0-65535) that distinguishes multiple network applications on one host; combined with the IP address it forms a socket. GLOSSARY
TCP
TCP (Transmission Control Protocol) is a connection-oriented, reliable, ordered transport-layer protocol, establishing connections with a three-way handshake and providing sliding-window flow control and ACK-based acknowledgment. GLOSSARY
UDP
UDP (User Datagram Protocol) is a connectionless, unreliable, unordered transport-layer protocol with low overhead and minimal delay, suited to real-time and broadcast traffic. GLOSSARY
IP Address
An IP address is the numeric identifier assigned to a network interface—32 bits for IPv4 (four decimal octets) and 128 bits for IPv6 (eight hexadecimal groups)—used for network addressing. GLOSSARY