HTTP over TCP requires a reliable, ordered, byte-stream connection between client and server, and the protocol itself defines the exact format of requests and responses exchanged over that connection. The core requirements are: a TCP connection (usually port 80 for HTTP, 443 for HTTPS), a request line with method and path, headers, an optional body, and a response with a status line, headers, and optional body.
Formula
The calculator above computes throughput (KB/s) as data divided by time: Throughput = Data / Time. In symbols: R = D / t, where R is throughput in kilobytes per second, D is data transferred in kilobytes, and t is the total time in seconds. The second output just converts the time to milliseconds for convenience.
Worked Example
Using the default values: response time = 0.5 s, data = 100 KB. Throughput = 100 / 0.5 = 200 KB/s. So the server delivers 200 kilobytes per second. The latency output is 0.5 × 1000 = 500 ms.
Background: Why HTTP Sits on TCP
HTTP (HyperText Transfer Protocol) is an application-layer protocol. It relies on TCP (Transmission Control Protocol) to provide a reliable connection. TCP guarantees that bytes arrive in order, without loss, and with error checking. This is essential because HTTP messages are plain text with a precise structure; a missing byte or reordered packet would break the request or response. UDP, by contrast, is faster but unreliable, so it is used for streaming or gaming, not for HTTP.
Historically, HTTP/1.1 opened a new TCP connection for each request, which was inefficient. Modern HTTP/2 and HTTP/3 improve on this: HTTP/2 multiplexes many requests over one TCP connection, while HTTP/3 uses QUIC (which runs over UDP) to avoid head-of-line blocking. However, the classic HTTP over TCP model remains the foundation.
How HTTP over TCP Works
The process follows a clear sequence:
- The client (browser or app) initiates a TCP three-way handshake with the server (SYN, SYN-ACK, ACK).
- The client sends an HTTP request message. A GET request looks like:
GET /index.html HTTP/1.1 Host: example.com User-Agent: Mozilla/5.0 Accept: text/html
The first line is the request line: method, path, protocol version. Then headers, a blank line, and optionally a body (for POST).
- The server parses the request, processes it, and sends an HTTP response. A typical response:
HTTP/1.1 200 OK Content-Type: text/html Content-Length: 1234 <html>...</html>
The status line has the version, status code, and reason phrase. Then headers and a body.
- The connection may be kept alive (HTTP/1.1 default) or closed (Connection: close).
The protocol requires that the client and server agree on the message format. The Host header is mandatory in HTTP/1.1, and the Content-Length header (or chunked transfer encoding) tells the receiver where the body ends.
What the Protocol Actually Requires
At the protocol level, HTTP specifies:
- Request line: method (GET, POST, PUT, DELETE, etc.), URI, and HTTP version.
- Status line: HTTP version, status code (200, 404, 500, etc.), and reason phrase.
- Headers: case-insensitive field names, followed by a colon and value. Headers are optional unless required by the method or version.
- Body: optional; if present, the length is indicated by Content-Length or chunked encoding.
- Connection management: HTTP/1.1 defaults to persistent connections, so the server must not close the connection unless told to.
For a server to be HTTP-compliant, it must parse these elements correctly. The TCP layer handles segmentation, flow control, and acknowledgments, so HTTP does not need to deal with packet ordering.
Common Misconceptions and Pitfalls
One common mistake is confusing HTTP with the underlying transport. HTTP is not a socket protocol; it is a message protocol that uses sockets. Another pitfall is forgetting that HTTP/1.1 requires the Host header. Without it, a server that hosts multiple domains cannot route the request correctly.
Another issue is the difference between persistent and non-persistent connections. In HTTP/1.0, each request needed a new connection, which caused latency. HTTP/1.1 introduced keep-alive, but some servers still close connections by default if not configured. Also, chunked transfer encoding is used when the response length is not known in advance, but the client must handle it.
Security is also a requirement in practice: HTTPS (HTTP over TLS) encrypts the TCP stream. The protocol itself does not require encryption, but modern web standards mandate it for most traffic.
How to Choose Between HTTP/1.1, HTTP/2, and HTTP/3
For most web applications, HTTP/2 is the default choice because it reduces latency through multiplexing and header compression. HTTP/3 uses QUIC over UDP, which is beneficial for mobile networks with frequent connection changes. However, HTTP/3 requires a different transport and is not yet universally supported on all servers and clients. For simple APIs, HTTP/1.1 is still perfectly adequate.
When building a custom server, you need to decide which version to support. HTTP/1.1 is easiest to implement manually, while HTTP/2 requires binary framing and compression. Most developers use existing libraries (like Node.js, Nginx, or Apache) that handle these details.
Common Problems and Troubleshooting
When HTTP over TCP fails, the issue is often at the TCP level, not HTTP. For example:
- Connection refused: The server is not listening on the port or a firewall blocks it.
- Timeout: The server is overloaded or the network is slow.
- Malformed request: The client sends invalid headers or a missing Host header.
- Partial responses: The server closes the connection before sending the full body, often due to a missing Content-Length.
Tools like curl and browser developer tools can show the exact request and response. A simple test is to use telnet or nc to send a raw HTTP request over TCP and see the server’s response.
Frequently Asked Questions
Does HTTP always require TCP?
No. HTTP/3 uses QUIC, which runs over UDP. However, HTTP/1.1 and HTTP/2 are defined over TCP. The protocol specification for HTTP/2 requires TCP, while HTTP/3 is designed for QUIC.
What port does HTTP use?
The default port is 80 for HTTP and 443 for HTTPS. You can use other ports, but clients assume these defaults unless specified in the URL.
What happens if a TCP packet is lost?
TCP retransmits the lost packet. HTTP does not see the loss; it just waits for the data to arrive. This reliability is why TCP is used for HTTP.
Can I send HTTP over a Unix socket?
Yes, but that is not standard. HTTP is typically sent over TCP/IP, but you can use Unix domain sockets for local communication, as long as both sides understand the HTTP message format.
Why is the Host header required?
In HTTP/1.1, the Host header is mandatory because a single server can host multiple domains. The header tells the server which virtual host to use.
What is keep-alive in HTTP?
Keep-alive (persistent connection) allows multiple requests and responses to be sent over the same TCP connection, reducing latency and overhead. HTTP/1.1 uses it by default.
Related
Formula used
in t | Response time (s) | s | 0.5 | 0 | 10 in d | Data transferred (KB) | KB | 100 | 0 | 100000 out rate | Throughput (KB/s) | KB/s | d / t | 2 out latency | Latency (ms) | ms | t * 1000 | 0
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Microsoft Surface Duo: The Foldable Phone Story
- Samsung SM-T813 Hard Reset: Step-by-Step Guide
- Mafia Clash Codes: Real Meanings & Usage
- Remove Programs from Mac: Full Uninstall Guide
- Project Sentinel Morning Digest: Data Stack Failure Alerts
- Best KVM VPS Hosting: Top Picks & Guide