Kodokon kodokon.com

How the internet works: client, server, request

Understand who asks what from whom when a web page appears on your screen.

7 min · 3 questions

Open this lesson in Kodokon

Picture a restaurant. You sit down, you call the waiter, you order a dish, and the waiter brings it to you. The web works in exactly the same way. You, with your browser, are the client: you are the one doing the asking. On the other side sits a server: a computer that is switched on around the clock, somewhere in an air-conditioned building, whose only job is to wait for requests and answer them. There is nothing magical about a server: it is a machine like yours, except it never sleeps and it has no screen.

The single most important thing to remember: the server never makes the first move. It sends you nothing until you have asked for something. Every time you type an address or click a link, your browser sends a request, and the server sends back a response. Request, response. Request, response. The entire web comes down to that back and forth.

For a request to reach its destination, every connected machine has an IP address: a series of numbers that acts as a postal address, for example 93.184.215.14. Your message is not sent in one piece: it is chopped into small chunks called packets, which each travel their own way through dozens of intermediate machines, then get reassembled in the right order on arrival. You can check that a machine answers with the ping command.

BASH
ping -c 2 example.com

PING example.com (23.215.0.136): 56 data bytes
64 bytes from 23.215.0.136: icmp_seq=0 ttl=54 time=17.3 ms
64 bytes from 23.215.0.136: icmp_seq=1 ttl=54 time=16.9 ms

--- example.com ping statistics ---
2 packets transmitted, 2 packets received, 0.0% packet loss
On Windows, write ping -n 2 example.com. The IP address you see may be different: that is normal.

And what exactly does the server send back? Text. A web page is nothing more than a text file written in HTML that the server ships to you and that your browser lays out. You can see this with your own eyes without a browser, using the curl tool, which sends a request and prints the raw response in the terminal.

BASH
curl -s https://example.com | head -n 5

<!doctype html>
<html>
<head>
    <title>Example Domain</title>
    <meta charset="utf-8" />
curl asks for the page, head -n 5 shows only the first 5 lines.

Knowledge check

Make sure you remember the key points of this lesson.

  1. In a web exchange, who makes the first move?
    • The server, which sends pages whenever it decides to
    • The client, meaning your browser
    • The home router, which hands out the pages
  2. What is a web server?
    • A computer switched on around the clock that answers requests
    • The cable that connects your home to the network
    • The program that displays pages on your screen
  3. A page contains a stylesheet and three images. Roughly how many requests does the browser send?
    • Just one, everything arrives together
    • Two: the page, then the files bundled together
    • At least five: one per file