The Client-Server Model
The client-server model is the dominant pattern for networked communication. A client initiates a request for a service; a server listens for requests and responds.
The Request-Response Cycle
- Client connects — the client opens a connection to the server at a known address (IP + port).
- Client sends a request — e.g., an HTTP
GET /productsmessage. - Server processes the request — it reads the request, does work (database query, computation), and prepares a response.
- Server sends the response — e.g., HTTP
200with the product data in JSON. - Client acts on the response — renders the data, or retries, or reports an error.
Why Not Peer-to-Peer for Everything?
Peer-to-peer (P2P) — where every node is both client and server — works well for file sharing (BitTorrent). But it is harder to secure, audit, and scale for services that manage user accounts, payments, or real-time state. Servers centralize these concerns.
Stateful vs. Stateless Servers
- Stateful — the server remembers something about the client between requests (e.g., a shopping cart stored in server memory).
- Stateless — each request is independent; the client sends all necessary context (e.g., a session token). HTTP is stateless by default.
Stateless servers are easier to scale (requests can be load-balanced to any instance) but shift the burden of state management to the client or a shared store.
Connection Management
A socket is an endpoint for communication — a (source IP, source port, destination IP, destination port) tuple. Each connection gets its own socket on both sides.
Learn how ports and sockets work in detail.
This article is part of the Networking From the Ground Up learning path.