Clients and Servers: The Model Behind Almost Everything Online
Understand who asks and who answers online, how ports and protocols fit in, how services scale and where peer-to-peer differs.
Key takeaways
- A client starts a conversation and a server listens for it; the same computer can play both roles.
- An IP address finds the machine, and a port number finds the particular service on it.
- Protocols define what requests and responses look like, so different vendors' software can work together.
- Large services place many servers behind one name, while peer-to-peer designs spread the serving role among users.
In the client-server model, one program (the client) sends a request, and another program (the server) waits for requests and answers them. Your browser asking for a page, your mail app checking for messages and your phone fetching a map tile all follow that pattern. Once you recognize it, a large share of online services starts to look like variations on one conversation.
The words describe roles, not hardware. A powerful machine in a data center can act as a client, and an old laptop on your desk can act as a server.
The basic exchange
A server program starts first and listens: it tells the operating system that it wants any traffic arriving on a certain port. It then waits, sometimes for a very long time.
A client knows or discovers the server's name or address, connects and sends a request. The server reads it, checks permissions, does some work and returns a response. The client uses the result, and the connection either closes or stays open for the next request.
Notice that the web server is a client of the database. Real services are full of these chains: a server handles your request by becoming a client of several other servers.
Addresses and ports
An IP address gets data to the right machine. A port, a number from 0 to 65535, gets it to the right program. Servers conventionally listen on well-known ports so clients know where to knock.
| Service | Typical port | Purpose |
|---|---|---|
| HTTP | 80 | Unencrypted web |
| HTTPS | 443 | Web over TLS or QUIC |
| DNS | 53 | Name lookups |
| SSH | 22 | Secure remote shell |
| SMTP submission | 587 | Sending mail from an app |
| IMAP over TLS | 993 | Reading mail |
| NTP | 123 | Time synchronization |
The client uses a port too, normally a temporary one picked by the operating system. The combination of both addresses, both ports and the transport protocol identifies a single conversation, which lets one server talk to thousands of clients on port 443 without mixing them up. More in ports explained.
Protocols: the shared language
A client and server need to agree on how to speak. A protocol defines the message formats, their order and what to do when something goes wrong. Because protocols such as HTTP, SMTP and IMAP are published openly, a client from one maker can talk to a server from another.
HTTP is the most familiar. A request names a method and a path; a response carries a status code, headers and usually a body.
curl -i https://example.com/ That command works as written on macOS and Linux; in Windows PowerShell, type curl.exe to be sure you get the real curl program. The -i option prints the response headers above the page content. You've just acted as a web client without a browser. Using curl to understand web requests shows more.
Thin clients, thick clients and APIs
Clients differ in how much work they do. A thin client mostly displays what the server prepares, like a simple web page generated on the server. A thick client holds more logic and data locally, like a desktop photo editor that syncs to an online account. Most modern apps sit between the two: the interface runs on your device, while shared data and rules live on servers.
Apps usually talk to servers through an API (application programming interface), a defined set of requests and responses meant for software and not for people. The same API can feed a website, an iPhone app and an Android app. That is one reason an outage can take down all of a company's apps at once while the apps themselves are fine.
One rule matters for anyone building these systems: the server can't trust the client. Users control their own devices, so checks such as "is this person allowed to see this order?" have to be enforced on the server, even if the app also hides the button.
State: remembering who you are
Plain HTTP treats each request independently. To remember that you signed in, the server gives the client something to send back, commonly a cookie or a token. The server then either looks up your session in its own storage or verifies the information in the token.
Anyone who steals that token can often act as you until it expires, which is why services send it only over encrypted connections and why signing out on a shared computer is worth the two seconds. See how cookies work.
How one name serves millions
A busy service can't live on one machine. It usually looks like a single server from outside while being many inside.
A load balancer distributes requests and stops sending them to machines that fail health checks. A cache avoids repeating expensive work. A content delivery network places copies of files near users. Related guides cover load balancers and reverse proxies.
In cloud computing, the "server" may be a virtual machine or a function that exists only while handling a request. The name "serverless" means you don't manage the machines; they still exist.
Peer-to-peer: when everyone serves
In a peer-to-peer design, participants exchange data directly and each can be both client and server. File-sharing systems that split files among many users are the classic case, and some calls send media directly between two devices.
Peer-to-peer reduces the load on central machines and can keep working when one participant leaves. It is harder to manage, though. Home routers with address translation make it awkward for devices to reach each other, so many systems still use central servers to introduce peers, or to relay traffic when a direct path fails. In practice a lot of applications are hybrids.
Many requests at once
A server rarely talks to one client at a time. Some designs hand each connection to its own process or thread. Others use a small number of workers that watch thousands of connections and act only on the ones with data waiting, which suits long-lived, mostly idle connections.
Either way, resources are finite: memory, processor time, database connections and network capacity. When requests arrive faster than they can be handled, they queue, responses slow down and eventually some are refused. Well-behaved servers apply rate limits, often answering with status 429, to keep one busy client from starving the rest.
Clients have duties too. If a request fails, retrying instantly and forever makes an overloaded service worse. Good software waits a little longer after each failure and adds some randomness so that thousands of clients don't all return at the same moment. The retry and backoff simulator lets you see the effect.
Who starts the conversation
In the basic model the server never calls first; it only answers. That is awkward for chat messages or live scores, where the server learns something new and the client doesn't know to ask. Developers handle this in a few ways. The client can poll, asking again at intervals. It can use long polling, where the server holds a request open until it has news. Or both sides can keep a channel open with WebSockets or server-sent events.
Phone notifications work through a related arrangement. The phone keeps a connection to a push service run by the platform maker, and app servers hand messages to that service for delivery. Your phone doesn't need a separate open connection for every app. See WebSockets and server-sent events.
Running a server yourself
You can try the model safely on your own machine. If Python is installed, run this in a folder containing a test file (on Windows the command may be python or py; on macOS and Linux it is often python3):
python3 -m http.server 8000 --bind 127.0.0.1 Then open http://127.0.0.1:8000/ in your browser. You'll see the folder listing, and the terminal will log each request. The --bind 127.0.0.1 part keeps the server reachable only from your own computer. This tool is for local experiments, not for public hosting.
Making a home server reachable from outside is a bigger step. It involves firewall rules or port forwarding, keeping software patched and accepting that automated scanners will find it. Check your provider's terms, and consider whether a VPN into your home network meets the need with less exposure.
What can go wrong, and where
Error messages often tell you which side has the problem.
- Connection refused: the machine answered, but nothing is listening on that port, or a firewall actively rejected it.
- Timeout: no answer came back; the machine may be down or traffic may be silently dropped.
- 4xx status: the server understood you but won't or can't fulfill this request.
- 5xx status: something failed on the server side.
- Works on one device only: suspect the client's configuration, cache or software version.
When many people lose access at once, the fault is usually on the serving side or in the network between. When it's just you, start with your own device and connection.