DEV Community

Aditya Pratap
Aditya Pratap

Posted on

TCP

There's a norm while asking for your crush's number, it starts with a "Hi", you don't usually go up to them and ask "Can i get your number", they might not know you, you will be rejected and who wants that.

Transmission Control Protocol (TCP)

TCP is a network protocol that is used for reliable transportation of data. When you send a web request, that request might be coming through a ton of hurdles, facing crazy monsters or even die in the path.
What really happens is the data packets you receive and send can face numerous problems,

  • Some packets get lost in the way.
  • Data packets get unordered/mixed.
  • Can receive duplicate packets.
  • Data could have been corrupted.

TCP helps with this, it's like a postal office for data you share and ensures that, data arrives reliably, in same order and fixes corrupted data.

TCP 3-Way Handshake

A TCP Connection is initialized by a procedure referred as 3-Way Handshake.

TCP 3-Way Handshake

  1. SYN (Synchronize) – The client says: “Hey, I’m here and want to talk. My sequence number is 121.”
  2. SYN-ACK (Synchronize + Acknowledge) – The server replies: “Heyo my mate! My sequence number is 404 and I got your 121.”
  3. ACK (Acknowledge) – The client responds: “Great! I got your 404 as well. Let’s deal now:>”

The connection is open now and the data can be transferred securely.

How Data Transfer Works in TCP

After the handshake,

  • TCP splits data into smaller segments (like sending letters in envelopes).
  • Each segment has a sequence number so that it can be ordered later.
  • The receiver replies ACKs for each segment received.
  • If a segment is lost, TCP automatically resends it. > Think of it like sending numbered letters in the mail. If receiver says “I didn’t get number 3,” you resend it again.

TCP Connection Closing

Just like you don’t hang up your crush mid-call, TCP also says bye politely when the chat is done.

  1. - FIN – The client says: “I’m done sending data.”
  2. - ACK – The server replies: “Gotcha, will talk later.”
  3. - FIN – The server says: “Byeeee”
  4. - ACK – The client confirms: “GooodByeee”

And that's time to disconnect the call.

Top comments (0)