Introduction to Sockets and Network Connections
HTTP describes what the client asks for and how the server reports the result. The network connection is the setting in which this request-response exchange takes place.
Try it: HTTP Request and Response
What really happens when a browser fetches a URL: DNS lookup, TCP connection, the exact HTTP/1.1 request text, how the server picks a status code (200, 301, 304, 404, 405, 500), and how a cache with max-age and ETag avoids or shortens the next request.
How it works
- Check the browser cache: a copy younger than its max-age is used with no request at all; an older one is revalidated with If-None-Match.
- Look up the host name to get an IP address (DNS), then open a TCP connection to port 80 (http) or 443 (https).
- Send the request line (method, path, HTTP/1.1), one header per line, a blank line, and the body if any.
- The server routes the path: missing → 404, wrong method → 405 with Allow, crash → 500, moved → 301 with Location, matching ETag → 304, otherwise 200 with Content-Type, Content-Length, ETag and Cache-Control.
- The client follows a 301 to its Location, stores a cacheable 200, or reuses its cached body after a 304.
Default run (17 steps): The browser will request GET http://data.pr4e.org/page1.htm, then visit it again 90 s later. Browser cache: on. … Done. Visit 1: 200; Visit 2: 304.
Simplified: A toy browser and one toy server on a simulated clock (fixed per-phase delays). The DNS resolver is a three-entry table, TLS is a single step with no real cryptography, every request opens a new connection (Connection: close), only 200 responses to GET are cached, and ETags are a toy hash of the body. No real network traffic is sent.
Loading the simulation…
From Connection to Web Page
When a web client communicates with a web server, the exchange follows a predictable pattern. The client connects, sends a request, the server processes that request, and the server sends a response. HTTP, the Hypertext Transfer Protocol, defines this communication as a standardized, text-based request-response model. This cycle is the foundation of web communication.
HTTP as the Communication Protocol
HTTP provides the rules for communication between a web client and a web server. It is standardized, which means the participants follow an agreed structure, and text-based, which means the request and response are organized as readable textual parts. The model is intentionally simple: the client sends a request, and the server returns a response.
HTTP describes what the client asks for and how the server reports the result. The network connection is the setting in which this request-response exchange takes place.
Reading a GET Request
An HTTP GET request identifies the resource the client wants. Its required structure includes the HTTP method, the resource path, and the protocol version. Header lines can provide additional request information. The request ends with a mandatory blank line, which separates the request headers from what follows.
A Request for a Resource
Identify the parts of a generated HTTP GET request.
- 1Method
GET identifies the HTTP method used by the client.
- 2Resource path
/articles identifies the requested resource path.
- 3Protocol version
HTTP/1.1 identifies the protocol version in this generated example.
- 4Header
Host: example.test is a header line carrying request metadata in this generated example.
- 5Blank line
The empty line marks the required end of the request headers.
The request communicates that the client wants the resource at /articles and then terminates its headers with a blank line.
The exact names and values of headers can vary, but their structural role is the same in this model: they are header lines that carry metadata. The essential GET pattern is the request line followed by header lines and a mandatory blank line.
Interpreting the Server Response
After processing the request, the server sends an HTTP response. The response has four structural parts: a status line, header lines containing metadata, a blank line separator, and a response body. The body contains the requested resource.
Reading a Generated Response
Identify the structural parts of a generated HTTP server response.
- 1Status line
HTTP/1.1 200 OK is the status line in this generated example.
- 2Header lines
Content-Type: text/plain is a header line containing response metadata in this generated example.
- 3Blank line
The empty line separates the response headers from the response body.
- 4Response body
Welcome to the articles resource is the body containing the requested resource in this generated example.
The client can distinguish the response status, its metadata, and the requested resource by reading the response in order.
The blank line has a structural purpose in both directions of the exchange. In a GET request, it marks the end of the request headers. In a server response, it separates response headers from the response body.
Tracing the Complete Exchange
The complete cycle can be traced as four connected stages. First, the client establishes a connection. Second, it sends an HTTP request such as a GET request. Third, the server processes that request. Fourth, the server sends an HTTP response, which the client receives and processes. Leaving out any of these stages gives an incomplete picture of web communication.
What do you think happens?
A client has connected to a server and sent a GET request. What must happen before the client can process the requested resource?
Reveal answer
The server processes the request and sends an HTTP response.
HTTP follows a request-response model. The connection provides the setting for communication, but the server must process the request and return a response containing a status line, headers, a separator, and the response body.
- The client connects to the server.
- The client sends a structured HTTP request.
- The server processes the request.
- The server sends a structured HTTP response.
- The client processes the response and its requested resource.
Mistakes in Message Structure
Common mistake Treating a GET request as only a resource path
What it looks likeWriting down /articles but ignoring the method and protocol version
Why it failsAn HTTP GET request specifies the method, resource path, and protocol version as part of its request structure.
Do this insteadRead the request line as a complete structure: method, resource path, and protocol version.
Common mistake Omitting the mandatory blank line at the end of a GET request
What it looks likeEnding immediately after the last header line
Why it failsThe blank line marks the end of the request headers.
Do this insteadInclude the blank line as the final structural part of the request.
Common mistake Confusing response headers with the response body
What it looks likeTreating metadata header lines as if they were the requested resource
Why it failsThe response headers contain metadata, while the response body contains the requested resource.
Do this insteadUse the blank line to distinguish the metadata section from the response body.
Common mistake Stopping the cycle after the connection
What it looks likeAssuming that connecting to a server completes the web communication
Why it failsThe complete cycle also requires a request, server processing, and a response.
Do this insteadTrace all stages from connection through response processing.
Practice the Trace
A client wants a resource from a web server. Describe the exchange in order, beginning with the connection and ending when the client processes the server's response. Then list the four structural parts of the response.
Hints
- Use the sequence: connection, request, server processing, response.
- For the response structure, begin with the status line.
- Remember the blank line separator before the response body.
| Message | Required structural parts |
|---|---|
| HTTP GET request | Method, resource path, protocol version, header lines, mandatory blank line |
| HTTP server response | Status line, header lines with metadata, blank line separator, response body |
A comparison of the two main HTTP messages introduced in this article.
Key Takeaways
- 1HTTP is a standardized, text-based protocol built around a request-response model.
- 2A GET request identifies a method, resource path, and protocol version, includes header lines, and ends with a mandatory blank line.
- 3An HTTP server response contains a status line, metadata headers, a blank line separator, and a body containing the requested resource.
- 4The complete web communication cycle is connection, request, server processing, response, and client processing.
- 5A network connection is only one stage; HTTP gives the exchange its request and response structure.
At a glance
- HTTP is a standardized, text-based protocol for communication between web clients and servers.
- A GET request contains a method, resource path, protocol version, header lines, and a mandatory blank line.
- A server response contains a status line, metadata headers, a blank-line separator, and the requested resource in its body.
- The complete HTTP cycle moves from connection to request, server processing, response, and client processing.