TCP From Scratch

Why TCP?


📑 On this page
  1. Without TCP
  2. Purpose of TCP
📚 TCP Connection EstablishmentPart 1 of 7
  1. 1. Why TCP?
  2. 2. How People and Computers communicate
  3. 3. TCP Terminology
  4. 4. How Port Numbers work
  5. 5. Problems a missing Packet cause
  6. 6. Purpose of Connection Establishment
  7. 7. Concept of Sequence Number & Acknowledgement

Every network has implemented TCP/IP model. Servers, PC's, laptops etc each within their own NIC card has TCP/IP code within it. As network engineers data-link/switching and network layer/routing are very common and easy. However, it is important to supplement this with TCP knowledge for cases where the application/server is running fine, but the user experience is bad, despite all the routes being there.

Without TCP

Here is a scenario if TCP does not exist. In our network topology we have Alice, David and Bob in separate networks.

Let's say Alice wants to use an application such as WhatsApp to communicate with David over the internet.

  1. Alice crafts her message "I Don't Love You" and sends it to the Application Layer of the TCP/IP model within her device.
  2. Since TCP does not exist, this is encapsulated and sent to the Network layer. Network Layer puts these as four separate packets for "I" "Don't" "Love" "You"
  3. Network layer attaches source and destination IP to the packet information for both of these which is known as the IP Header. How it knows the destination? It gets this IP information from the Application Layer Data.
  4. This is then further encapsulated into a L2 Frame with Source & Destination MAC.
  5. If destination MAC is unknown ARP is done - Finally the Frame is sent on the physical Ethernet Wire.
  6. Internet then routes this to David. There may be multiple paths to reach David.

So what's the issue? Well Lets say if traffic flows through R1 -> R2 ->R4 -> David. If R2 is very congested and was unable to send the "Dont" so it dropped this. But R2 was able to send "I", "Love" "You". David Receives these packets de-encapsulates it and the network layer forwards it to David's Application Layer. David may be happy with this outcome but it was not Alice's intention. This causes an incomplete message.

It is not network layer responsibility to check for this dropped packet. Network layer responsibility is just to look at source and destination IP Addresses and forward them according to its routing table. If a congested router drops this packet before it can evaluate it then this is not Network Layer problem. Network Layer makes 0 direct connection with David and does not track for any errors.

Tip

IP (Internet Protocol) is a connectionless Protocol. It does not track connections. It just sees IP addresses and sends it.

Purpose of TCP

As you can now understand, TCP's purpose is to track these connections, to check for any errors or packets that have been dropped, and to figure out if retransmission of packets is required.

The way TCP does this at a high level via numbering/sequencing packets. "I" is packet number 1, "Don't" is 2, "Love" is 3 "You" is 4. If David's application receives 1,3,4 but not 2 then it knows there is an issue in the communication.

Comments