Two roles in every conversation
Almost everything on the web follows one pattern. One side asks, the other answers. The side that asks is the client. The side that answers is the server. After this lesson you will be able to point at any piece of the web and say which role it plays, and you will have run a real server yourself.
A client is any program that sends requests. Your browser is the best-known client, but a phone app that loads data, a script that checks the weather, and the curl command-line tool are clients too. A server is a program that waits for requests and sends back responses.
Notice the direction. The client always speaks first. A server does not send a page to a browser that has not asked for one. (There are techniques for live updates, but they begin with the client opening a connection.)
A server is a program, not a special machine
People say "the server" for both the program and the computer it runs on, which causes confusion. Keep them apart:
- The server program is software such as a web server application. It listens on a port and answers requests.
- The server computer is whatever machine runs it. In a data centre it is a computer with no screen, always on and well connected. But it is still a computer. Your laptop could run the same program.
What makes a machine "a server" is the job it does. Your laptop is a client when your browser loads a page and a server when you run a web server on it.
This is also why a hosting company can run a thousand small websites on one machine, as Web servers and hosting will show. The server program looks at which site each request is for and serves the right files.
Run a server in under a minute
You can try this if you have Python installed (it ships with many systems). Make an empty folder, put a file called index.html inside, and open a terminal there.
<!doctype html>
<title>Test bakery</title>
<h1>Fresh bread at 7am</h1>Save that as index.html. Then start Python's built-in server on a port of your choice:
python3 -m http.server 8000Open http://localhost:8000 in your browser. You will see the heading. The terminal prints a line for each request, which is the server telling you what the client asked for. Press Ctrl+C to stop it.
Now ask for the page without a browser. In a second terminal window run curl -i http://localhost:8000/. Below is output from a small server written for this course, captured on 2026-11. Yours will differ, especially the Server and Date lines.
HTTP/1.0 200 OK
Server: BaseHTTP/0.6 Python/3.9.6
Date: Sat, 14 Nov 2026 21:37:47 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 22
Hello from the bakeryTwo clients, a browser and curl, asked the same server and got the same kind of answer. That is the point of a standard protocol: any client can talk to any server.
localhost, and why it does not leave your computer
The name localhost always means "this computer". Requests to it never cross the network, so it is safe for experiments. A later lesson, IP addresses and ports, explains the numeric address behind it and why :8000 was needed in the URL.
What a server does with a request
When a request arrives, the server program typically does one of three things:
- Serve a file. The path maps to a file on disk, as in the example above.
- Run code. The path triggers a program that builds a page, perhaps by reading a database. The visitor cannot tell the difference.
- Refuse or redirect. The server answers with an error or points the client somewhere else.
Either way, the client receives a response. Servers also handle many clients at once. Your request is one of many arriving every second, and the server software is built to juggle them.
More than one server behind one site
A small site may live on one machine. Larger sites split the work: one group of servers builds pages, another stores data, another handles images, and some sit in front as a shield. The visitor still sees one address. This is just the client-server idea repeated, because each part is a client of the next. Your browser talks to a front server, which in turn may ask a database server for data. In that moment the front server is a client.
Common mistakes
- Using "server" and "computer" as if they were the same thing. A server is a role played by a program.
- Believing the server can reach into your browser whenever it likes. It answers requests the client started.
- Forgetting the port when testing locally. A server on port 8000 is not reachable at
http://localhost/, which uses the default port. - Leaving a local test server running and exposed on a network you do not control. Stop it when you finish.
Exercise
- Start a local server with the command above and load it in a browser, then with
curl -i. Compare what each shows. - Add a second file,
about.html, and request/about.html. Then request/missing.html. What differs? - List three clients and three servers you used today without noticing.
Show one possible answer
- The browser draws the page.
curl -iprints the status line, headers and raw HTML. The server sent the same thing to both. /about.htmlreturns a normal success response with your file./missing.htmlreturns a "404 Not Found" error response, because no such file exists.- Clients: a browser, a mail app, a weather widget on your phone. Servers: the website host, the mail provider, the weather service. Your own answers will differ.
Key points
- A client starts a conversation by sending a request, and a server waits and replies.
- A server is a program that listens on a port, usually running on a computer that stays on and connected.
- The same computer can be a client in one moment and a server in the next, and you can run a server on your own laptop.
- The web follows a simple pattern, request then response, and the server never pushes a page to a browser that has not asked.