Table of Contents

TCP vs HTTP

What is TCP?

TCP (Transmission Control Protocol) is a transport-layer protocol. It provides a reliable, ordered byte-stream connection between two endpoints (client and server).

TCP is like a pipe that carries bytes.

What is HTTP?

HTTP (Hypertext Transfer Protocol) is an application-layer protocol. It defines how to format requests and responses (methods like GET/POST, headers, body, status code).

HTTP runs on top of TCP (most commonly).

Key idea

So the correct mental model is:

Diagram (layering)

Example: Using TCP for HTTP (manual)

You can open a TCP connection and send an HTTP request manually:

conn, _ := net.Dial("tcp", "example.com:80")
defer conn.Close()
 
fmt.Fprint(conn, "GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n")
io.Copy(os.Stdout, conn)

Instead of crafting bytes yourself, use `http.Client`:

resp, err := http.Get("http://example.com/")
if err != nil { return }
defer resp.Body.Close()

When to use which

Hard words (English)