Client and Server

⏱ 6 min read

In one sentence: On a network, a client is a program that asks for something, and a server is a program that waits for requests and answers them.

Why should I care?

You have used clients and servers many times today. Your web browser is a client. When you open a web page, your browser asks another computer for it. A program on that computer, the server, answers by sending the page.

The same pattern is behind much of what you do on a network. Wikipedia's article on the client–server model names email and the World Wide Web (a system of connected web pages that you reach through the internet) as examples. When you build a website, you will put it on a server, and your visitors' browsers will be the clients.

Analogy

Think of the help desk in a library.

  • You walk to the desk and ask for a book. You are like the client.
  • The librarian waits at the desk for people to come. When you ask, the librarian looks for the book and gives you an answer: the book, or "sorry, we do not have it". The librarian is like the server.
  • You always speak first. The librarian does not call you at home to offer books.

Where the analogy breaks down: a librarian lends you the book itself, and you must bring it back. A server sends you a copy of the information and keeps the original, so many people can get the same page. A server can also answer many clients at almost the same time. And "client" and "server" are not people. They are roles: jobs that programs do.

How it actually works

A client is a program that asks for something. A server is a program that offers something and answers. The question is called a request, and the answer is called a response.

Here is what happens, step by step:

  1. The server waits. A server program runs on a computer and waits for requests. The Wikipedia article says that clients start the communication, and servers wait for requests to come in.
  2. The client sends a request. For example, your browser sends a message that asks for one web page. (How your browser finds the right computer is a later topic: DNS.)
  3. The server looks for the answer. For example, it looks for the page in its storage.
  4. The server sends a response. If it has the page, it sends a copy. MDN, a website that documents how the web works, says the client gets a copy of the page from the server. If the server cannot find the page, it says so. You may have seen this as a "404 Not Found" page. MDN explains that this means the server cannot find what was asked for.
  5. The client uses the response. Your browser shows the page on your screen.
A client asks, a server answersOn the left is the client, your browser. On the right is the server, a program on another computer that waits for requests. First the client sends a request: please send this page. Then the server sends a response: here is a copy.ServerClientWaits forrequests1. Request: pleasesend this page2. Response: here isa copy

One server, many clients. The Wikipedia article says a server may get requests from many different clients in a short time.

Programs, not computers. The words client and server describe programs. Browsers and web servers talk to each other with a set of rules called HTTP. The official description of HTTP says this clearly. A client is a program that contacts a server to send requests. A server is a program that accepts this contact and sends responses. It also says: "The same program might act as a client on some connections and a server on others." For example, a program might answer requests from browsers, and at the same time ask another server for something it needs.

People also use the word "server" for the computer that runs a server program. MDN calls this a hardware server: a shared computer on a network, usually a powerful one. You will learn more about these computers in Server.

(This is simplified. Requests and responses follow shared rules, called Protocols.)

How it came to be

The idea is older than the web. In 1969, researchers building ARPANET, the early computer network you read about before, used the words "server-host" and "user-host" for the two sides. A host is a computer on the network. One example is RFC 5, written by Jeff Rulifson in June 1969. (RFCs are documents that describe how computer networks and the internet work.)

The word "client" came later. The Wikipedia article says that an early use of it was in a 1978 paper (a written research report). Its writers were three computer scientists at Xerox PARC (Palo Alto Research Center): Howard Sturgis, James Mitchell and Jay Israel.

🧪 Try it in your browser

You will act as a client and see the server's answers. This works on a computer or a phone. It only looks. It changes nothing.

  1. Click this link: en.wikipedia.org/wiki/Special:Random.
  2. Wait for the page to appear. Note the title of the article. On a computer, the address at the top has changed to that article's address.
  3. Come back to this page. On a computer, use your browser's Back button, or close the new tab if one opened. On a phone, use your phone's usual way to go back.
  4. Click the same link again.

What you should see: each time, a Wikipedia article appears. The two articles are most likely different. Wikipedia's help pages say this link is used "to access a random article". Wikipedia runs on a program called MediaWiki. Its help pages add: "Users will be redirected to the selection." (Redirected means sent on to another address.)

What happened: your browser, the client, sent the same request twice, to the same address. The request did not say which article to send. Wikipedia picked an article and answered with a redirect: "go to this article instead". MDN explains that a server sends this kind of response, and the browser then loads the new address. So the client asks, and the server decides what to send back.

What happens when you click Special:RandomYour browser, the client, asks Wikipedia for the address Special:Random. Wikipedia picks an article and answers with a redirect: go to this article instead. The browser then loads the new address, and Wikipedia sends the article.WikipediaYourbrowserPicks anarticleRequest:Special:RandomRedirect: go to thisarticle insteadRequest: the newaddressThe article

Common misunderstandings

  • "A server is a special kind of computer." Not necessarily. A server is a program that answers requests. People also call the computer that runs it a server, and those computers are usually powerful. But the Wikipedia article says that client and server "may be on the same device".
  • "The server sends me pages whenever it wants." No. In the client–server way of working, the client starts. The server waits and answers.
  • "Every network works with clients and servers." No. In another design, called peer-to-peer, the computers are equals, called peers. The Wikipedia article says that "peers communicate with each other directly".

Recap

  • A client is a program that sends a request. A server is a program that waits for requests and sends responses.
  • The client starts the conversation. The server decides what to answer, and one server can answer many clients.
  • Client and server are roles. The same program can be a client in one connection and a server in another.

Sources

Written with AI · Reviewed by AI · Not yet checked by a human

Found a mistake, or something you did not understand? Report a problem.