<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[3-Way Handshake & Reliable Communication]]></title><description><![CDATA[3-Way Handshake & Reliable Communication]]></description><link>https://akshay3-wayhandshaake.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Mon, 21 Sep 2026 13:36:12 GMT</lastBuildDate><atom:link href="https://akshay3-wayhandshaake.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[TCP Working: 3-Way Handshake & Reliable Communication]]></title><description><![CDATA[Every time you load a website, there's a handshake happening between your computer and the server. Let me show you how TCP makes sure your data actually arrives.
What Happens Without Rules?
Imagine shouting your order at a drive-through without check...]]></description><link>https://akshay3-wayhandshaake.hashnode.dev/tcp-working-3-way-handshake-and-reliable-communication</link><guid isPermaLink="true">https://akshay3-wayhandshaake.hashnode.dev/tcp-working-3-way-handshake-and-reliable-communication</guid><category><![CDATA[Web Development]]></category><category><![CDATA[ChaiCode]]></category><category><![CDATA[TCP]]></category><category><![CDATA[3wayhandshake]]></category><dc:creator><![CDATA[Akshay Singh]]></dc:creator><pubDate>Sat, 14 Feb 2026 20:13:37 GMT</pubDate><content:encoded><![CDATA[<p>Every time you load a website, there's a handshake happening between your computer and the server. Let me show you how TCP makes sure your data actually arrives.</p>
<h2 id="heading-what-happens-without-rules">What Happens Without Rules?</h2>
<p>Imagine shouting your order at a drive-through without checking if anyone's listening. Maybe they hear you, maybe they don't. Maybe your order arrives scrambled.</p>
<p>That's the internet without TCP:</p>
<ul>
<li><p>Packets arrive out of order</p>
</li>
<li><p>Some packets never arrive</p>
</li>
<li><p>No way to know if the other side received anything</p>
</li>
<li><p>Complete chaos</p>
</li>
</ul>
<p>That's why we need TCP.</p>
<h2 id="heading-what-is-tcp">What is TCP?</h2>
<p>TCP (Transmission Control Protocol) is like having a careful conversation. Before sending anything important, both sides confirm they're ready. Then they keep checking "did you get that?" after each message.</p>
<p><strong>TCP = Registered mail with tracking</strong><br /><strong>No TCP = Throwing messages in bottles into the ocean</strong></p>
<h2 id="heading-the-tcp-3-way-handshake">The TCP 3-Way Handshake</h2>
<p>Before sending any real data, TCP does a handshake. Think of it like a phone call:</p>
<p><strong>You:</strong> "Hello?"<br /><strong>Friend:</strong> "Hey! I can hear you!"<br /><strong>You:</strong> "Great! Let's talk!"</p>
<p>That's literally what happens, but with SYN and ACK packets.</p>
<h3 id="heading-step-1-syn-client-to-server">Step 1: SYN (Client to Server)</h3>
<pre><code class="lang-plaintext">Client ──────── SYN ──────── ▶ Server
        "Can we talk? My starting number is 1000"
</code></pre>
<p>The client sends a SYN packet saying "I want to connect, and here's my sequence number."</p>
<h3 id="heading-step-2-syn-ack-server-to-client">Step 2: SYN-ACK (Server to Client)</h3>
<pre><code class="lang-plaintext">Client ◀──────── SYN-ACK ──────── Server
       "Yes! My number is 5000, and I got your 1000"
</code></pre>
<p>The server responds: "I'm ready too! Here's MY sequence number, and yes, I got yours."</p>
<h3 id="heading-step-3-ack-client-to-server">Step 3: ACK (Client to Server)</h3>
<pre><code class="lang-plaintext">Client ──────── ACK ──────── ▶ Server
        "Got your 5000! Let's go!"
</code></pre>
<p>The client confirms: "Got it! Connection established!"</p>
<p><strong>Connection is now open</strong> and data can flow.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1771100985666/321d4cba-60f9-4c67-a235-4d7535607ae9.png" alt /></p>
<h2 id="heading-why-three-steps">Why Three Steps?</h2>
<p>Both sides need to:</p>
<ol>
<li><p>Announce their starting sequence number</p>
</li>
<li><p>Acknowledge the other side's number</p>
</li>
</ol>
<p>Three steps is the minimum to sync both ways. That's why it's called the "3-way handshake."</p>
<h2 id="heading-how-data-transfer-works">How Data Transfer Works</h2>
<p>Once connected, data flows with sequence numbers tracking everything.</p>
<p><strong>Example:</strong></p>
<pre><code class="lang-plaintext">Client sends: "Hello" (seq=1000, 5 bytes)
Server ACKs:  ack=1005 (got it, send 1005 next)

Client sends: "World" (seq=1005, 5 bytes)  
Server ACKs:  ack=1010 (got it, send 1010 next)
</code></pre>
<p>Every byte gets a number. The server acknowledges what it received and what it expects next.</p>
<h2 id="heading-how-tcp-ensures-reliability">How TCP Ensures Reliability</h2>
<p><strong>1. Acknowledgments (ACKs)</strong></p>
<p>Every packet must be acknowledged. No ACK? Resend it.</p>
<pre><code class="lang-plaintext">Client ───── Packet ─────▶ Server
Client ◀──── ACK ───────── Server  ✓ Good!

Client ───── Packet ─────▶ ❌ Lost!
Client    ...timeout...no ACK
Client ───── Packet ─────▶ Server  (Resend!)
Client ◀──── ACK ───────── Server  ✓ Success!
</code></pre>
<p><strong>2. Sequence Numbers Keep Order</strong></p>
<p>Packets might arrive scrambled. TCP uses sequence numbers to reorder them.</p>
<pre><code class="lang-plaintext">Sent:     1 → 2 → 3 → 4
Arrived:  1 → 3 → 2 → 4
TCP puts: 1 → 2 → 3 → 4  ✓
</code></pre>
<p><strong>3. Checksums Detect Corruption</strong></p>
<p>Each packet has a checksum. If data gets corrupted, checksum fails, TCP requests a resend.</p>
<p><strong>4. Flow Control</strong></p>
<p>TCP makes sure the sender doesn't overwhelm the receiver. The receiver says "I can handle this much" and the sender adjusts.</p>
<h2 id="heading-how-tcp-closes-a-connection">How TCP Closes a Connection</h2>
<p>When done, you can't just hang up. You need to close properly with FIN packets:</p>
<pre><code class="lang-plaintext">Client ───── FIN ─────▶ Server  ("I'm done")
Client ◀──── ACK ────── Server  ("OK")
Client ◀──── FIN ────── Server  ("I'm done too")
Client ───── ACK ─────▶ Server  ("Bye!")
</code></pre>
<p>Four steps (4-way handshake) to close cleanly.</p>
<h2 id="heading-the-complete-tcp-3-way-handshake">The Complete TCP 3- Way handshake</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1771099895900/70c1ac54-5b76-4841-8887-14f49a2d5d23.webp" alt class="image--center mx-auto" /></p>
<h2 id="heading-real-world-example">Real-World Example</h2>
<p>When you visit <a target="_blank" href="http://google.com">google.com</a>:</p>
<ol>
<li><p><strong>Handshake:</strong> Your browser and Google's server do SYN → SYN-ACK → ACK</p>
</li>
<li><p><strong>Request:</strong> Browser sends "GET / HTTP/1.1" with sequence numbers</p>
</li>
<li><p><strong>Response:</strong> Google sends HTML back with ACKs</p>
</li>
<li><p><strong>Close:</strong> Both sides send FIN and ACK to disconnect</p>
</li>
</ol>
<p>All of this happens in milliseconds. You never see it, but it's happening constantly.</p>
<h2 id="heading-why-this-matters">Why This Matters</h2>
<p>Every time you:</p>
<ul>
<li><p>Load a website</p>
</li>
<li><p>Send an email</p>
</li>
<li><p>Use an API</p>
</li>
<li><p>Download a file</p>
</li>
</ul>
<p>TCP is:</p>
<ul>
<li><p>Handshaking before starting</p>
</li>
<li><p>Numbering every byte</p>
</li>
<li><p>Confirming delivery</p>
</li>
<li><p>Retransmitting lost packets</p>
</li>
<li><p>Keeping everything in order</p>
</li>
<li><p>Closing cleanly when done</p>
</li>
</ul>
<h2 id="heading-summary">Summary</h2>
<p><strong>3-Way Handshake:</strong></p>
<ol>
<li><p>Client: "Can we talk?" (SYN)</p>
</li>
<li><p>Server: "Yes! You there?" (SYN-ACK)</p>
</li>
<li><p>Client: "Yep, let's go!" (ACK)</p>
</li>
</ol>
<p><strong>Reliable Transfer:</strong></p>
<ul>
<li><p>Sequence numbers track order</p>
</li>
<li><p>ACKs confirm delivery</p>
</li>
<li><p>Lost packets get resent</p>
</li>
<li><p>Checksums catch corruption</p>
</li>
</ul>
<p><strong>Clean Close:</strong></p>
<ul>
<li><p>Both sides send FIN</p>
</li>
<li><p>Both sides ACK</p>
</li>
<li><p>Connection closed</p>
</li>
</ul>
<p>That's TCP! It costs a bit more time (handshakes, ACKs), but you get guaranteed delivery.</p>
]]></content:encoded></item></channel></rss>