Computer networks¶
~12 min
In short¶
A computer network moves data between machines using agreed rules called protocols. This page explains the layered model, the protocols you will meet most often (IP, TCP, UDP, DNS, HTTP), and how a single web request travels across them. Learn that path first. Most networking topics are details around it.
What the subject is about¶
Networking is built in layers. Each layer does one job and relies on the layer below. The application layer holds protocols such as HTTP and DNS. The transport layer, using TCP or UDP, delivers data between programs on two machines. The network layer, using IP, moves packets between networks. The link layer moves frames across a single physical link such as Ethernet or Wi-Fi.
IP addresses identify machines, and port numbers identify programs on a machine. TCP adds reliability: it numbers the bytes, retransmits what is lost, and controls how fast the sender goes. UDP sends independent datagrams with no such guarantees, which suits real-time media and simple queries.
DNS turns names such as example.com into IP addresses. HTTP is the request and response protocol that web browsers and many APIs use. HTTP usually runs over TCP, and TLS adds encryption on top.
Sockets are the programming interface. Your program opens a socket, connects or listens, then sends and receives bytes.
What to learn first¶
- The layered model and what each layer is responsible for.
- IP addresses, and the difference between a public and a private address.
- Ports, and why a server listens on a port.
- TCP: connection setup, reliable delivery, and closing a connection.
- UDP: when no guarantees are acceptable.
- DNS: resolving a name to an address.
- HTTP: methods, status codes, headers, and a request and response pair.
- TLS at the idea level: encryption and certificates.
- Sockets: creating a server that accepts one connection and echoes a line.
- Latency, bandwidth, and why a round trip takes time.
For a hands-on start, the backend lessons in ../../python/08-backend/01-http-request-lifecycle.md walk through a request from browser to server. ../../python/08-backend/05-a-small-rest-service.md shows the same ideas as code.
What you can skip at first¶
- Routing protocols such as OSPF and BGP. Know that routers pick paths; leave the algorithms for later.
- Subnet mask arithmetic beyond the basic idea of a network prefix.
- Wireless radio details.
- Writing a TCP stack. Read about it, but use the operating system's implementation.
- Firewall rule syntax for a specific product.
How it connects to the other subjects¶
The operating system provides sockets and runs the server processes or threads that handle connections. See operating systems.
Databases are usually reached over the network. Connection pools and round-trip time shape how fast an application feels. See databases.
Hashing and trees appear in routing tables and DNS caches. See data structures and algorithms.
For a larger view of how networked services are designed, the site's ../../systems-engineering/hld/index.md covers high-level design, and the networking topics there build on what you learn here.
Free resources¶
- Computer Networking: A Top-Down Approach, Kurose and Ross (https://gaia.cs.umass.edu/kurose_ross/). The textbook's companion site with slides and labs. It suits a student who wants a standard, readable text with exercises.
- Beej's Guide to Network Programming (https://beej.us/guide/bgnet/). A short free guide to sockets in C, with clear examples. It suits someone who wants to write a client or server soon.
- MDN Web Docs, HTTP overview (https://developer.mozilla.org/en-US/docs/Web/HTTP/Overview). A clear, practical overview of HTTP for web developers. It suits anyone building a web page or API.
- RFC 9110, HTTP Semantics (https://www.rfc-editor.org/rfc/rfc9110). The formal specification for HTTP's meaning of methods, status codes, and headers. It suits someone who wants to check exactly what a status code means.
Practice¶
- Run a command that resolves a domain name to its addresses, then write down the IP addresses you get and the command you used.
- Make an HTTP request to a public test site with
curl -v. Identify the method, the status code, and two response headers. - Write a Python server that listens on a port, accepts one connection, reads one line, and sends it back in upper case. Connect to it with
telnetornc. - Explain in five sentences what happens between typing a URL and seeing the first byte of the page. Name the layers involved.
- Compare TCP and UDP for a chat application and for a video call. For each, say which protocol you would choose and why, in two sentences.
Sources¶
- Kurose and Ross, Computer Networking: A Top-Down Approach, companion site, https://gaia.cs.umass.edu/kurose_ross/
- Beej, Beej's Guide to Network Programming, https://beej.us/guide/bgnet/
- MDN Web Docs, An overview of HTTP, https://developer.mozilla.org/en-US/docs/Web/HTTP/Overview
- IETF, RFC 9110: HTTP Semantics, https://www.rfc-editor.org/rfc/rfc9110
- IETF, RFC 9293: Transmission Control Protocol (TCP), https://www.rfc-editor.org/rfc/rfc9293
- IETF, RFC 1034: Domain names - concepts and facilities, https://www.rfc-editor.org/rfc/rfc1034