<?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[TCP Working: 3-Way Handshake]]></title><description><![CDATA[TCP Working: 3-Way Handshake]]></description><link>https://handshake-tcp.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Wed, 09 Sep 2026 06:48:13 GMT</lastBuildDate><atom:link href="https://handshake-tcp.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[Hello friendsToday we will go deep into TCP and understand:

Why TCP is needed

What is 3-Way Handshake

How TCP sends data safely

How TCP closes connection



Why TCP is Needed?
Imagine you want to send a file to your friend.
The file is broken int...]]></description><link>https://handshake-tcp.hashnode.dev/tcp-working-3-way-handshake-and-reliable-communication</link><guid isPermaLink="true">https://handshake-tcp.hashnode.dev/tcp-working-3-way-handshake-and-reliable-communication</guid><category><![CDATA[TCP]]></category><category><![CDATA[3-way handshake]]></category><category><![CDATA[#3-way handshaking]]></category><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[ChaiCohort]]></category><category><![CDATA[chai-code ]]></category><category><![CDATA[chai aur code]]></category><dc:creator><![CDATA[Kedar]]></dc:creator><pubDate>Mon, 26 Jan 2026 13:46:33 GMT</pubDate><content:encoded><![CDATA[<p>Hello friends<br />Today we will go <strong>deep into TCP</strong> and understand:</p>
<ul>
<li><p>Why TCP is needed</p>
</li>
<li><p>What is <strong>3-Way Handshake</strong></p>
</li>
<li><p>How TCP sends data safely</p>
</li>
<li><p>How TCP closes connection</p>
</li>
</ul>
<hr />
<h2 id="heading-why-tcp-is-needed">Why TCP is Needed?</h2>
<p>Imagine you want to send a file to your friend.</p>
<p>The file is broken into <strong>many small packets</strong>:</p>
<pre><code class="lang-plaintext">Packet 1, Packet 2, Packet 3, ...
</code></pre>
<p>If there are <strong>no rules</strong>:</p>
<ul>
<li><p>Packet 5 may get lost</p>
</li>
<li><p>Packet 10 may come before packet 1</p>
</li>
<li><p>Packet 20 may get damaged</p>
</li>
</ul>
<p>Final result<br />File becomes <strong>useless garbage</strong></p>
<p>So internet needed a protocol that can say:</p>
<ul>
<li><p>Send in order</p>
</li>
<li><p>Check if packet reached</p>
</li>
<li><p>Resend if lost</p>
</li>
<li><p>Make sure data is correct</p>
</li>
</ul>
<p><strong>That protocol is TCP</strong></p>
<hr />
<h2 id="heading-what-is-tcp">What is TCP</h2>
<p><strong>TCP = Transmission Control Protocol</strong></p>
<p>TCP is a <strong>transport protocol</strong> which ensures:</p>
<ul>
<li><p>Reliability</p>
</li>
<li><p>Order</p>
</li>
<li><p>Correctness</p>
</li>
</ul>
<p>TCP says:</p>
<blockquote>
<p>“Don’t worry, I will deliver your data properly.”</p>
</blockquote>
<hr />
<h2 id="heading-tcp-connection">TCP Connection</h2>
<p>TCP does not send data directly.</p>
<p>First it says:</p>
<blockquote>
<p>“Let us confirm both sides are ready”</p>
</blockquote>
<p>This process is called<br /><strong>3-Way Handshake</strong></p>
<hr />
<h2 id="heading-what-is-3-way-handshake">What is 3-Way Handshake?</h2>
<p>3-Way Handshake is <strong>connection setup process</strong> of TCP.</p>
<p>Why 3 steps?<br />Because <strong>both sides must agree</strong> before data transfer.</p>
<hr />
<h2 id="heading-analogy">Analogy</h2>
<p>Think of two friends:</p>
<ul>
<li><p><strong>a</strong> → Client</p>
</li>
<li><p><strong>b</strong> → Server</p>
</li>
</ul>
<p>They are using walkie-talkie</p>
<hr />
<h2 id="heading-step-by-step-3-way-handshake">Step-by-Step 3-Way Handshake</h2>
<h3 id="heading-step-1-syn">Step 1: SYN</h3>
<p>a says:</p>
<blockquote>
<p>“Hello b! Can you hear me?”</p>
</blockquote>
<p>Technical meaning:</p>
<ul>
<li><p>Client sends <strong>SYN packet</strong></p>
</li>
<li><p>SYN = Synchronize</p>
</li>
<li><p>Means: “I want to start connection”</p>
</li>
</ul>
<hr />
<h3 id="heading-step-2-syn-ack">Step 2: SYN-ACK</h3>
<p>b replies:</p>
<blockquote>
<p>“Yes a, I can hear you. Can you hear me?”</p>
</blockquote>
<p>Technical meaning:</p>
<ul>
<li><p>Server sends <strong>SYN + ACK</strong></p>
</li>
<li><p>ACK = Acknowledge</p>
</li>
<li><p>Means: “I heard you, and I am ready too”</p>
</li>
</ul>
<hr />
<h3 id="heading-step-3-ack">Step 3: ACK</h3>
<p>Rahul replies:</p>
<blockquote>
<p>“Yes b, I can hear you too. Let’s talk.”</p>
</blockquote>
<p>Technical meaning:</p>
<ul>
<li><p>Client sends <strong>ACK</strong></p>
</li>
<li><p>Now connection is <strong>ESTABLISHED</strong></p>
</li>
</ul>
<hr />
<p><img src="https://miro.medium.com/0%2AWcbPv9sWlCl6RV4a" alt="https://miro.medium.com/0%2AWcbPv9sWlCl6RV4a" /></p>
<hr />
<h2 id="heading-after-handshake-data-transfer-starts">After Handshake: Data Transfer Starts</h2>
<p>Now both client and server trust each other.</p>
<p>Data starts flowing in <strong>segments</strong>.</p>
<p>But TCP still does checking.</p>
<hr />
<h2 id="heading-how-tcp-sends-data-safely">How TCP Sends Data Safely</h2>
<p>TCP adds <strong>extra information</strong> with every packet:</p>
<ul>
<li><p><strong>Sequence Number</strong></p>
</li>
<li><p><strong>Acknowledgement Number</strong></p>
</li>
</ul>
<h3 id="heading-sequence-number">Sequence Number</h3>
<p>Tells:</p>
<blockquote>
<p>“This is packet number X”</p>
</blockquote>
<h3 id="heading-acknowledgement-number">Acknowledgement Number</h3>
<p>Tells:</p>
<blockquote>
<p>“I received till packet number X”</p>
</blockquote>
<hr />
<p><img src="https://media.geeksforgeeks.org/wp-content/uploads/20250513105835416942/tcp.webp" alt="https://media.geeksforgeeks.org/wp-content/uploads/20250513105835416942/tcp.webp" /></p>
<hr />
<h2 id="heading-what-if-packet-is-lost">What if Packet is Lost?</h2>
<p>Suppose:</p>
<ul>
<li>Packet 5 is lost</li>
</ul>
<p>Receiver says:</p>
<blockquote>
<p>“I received till packet 4 only”</p>
</blockquote>
<p>Sender understands:</p>
<blockquote>
<p>“Packet 5 missing”</p>
</blockquote>
<p>TCP will:</p>
<ul>
<li><p><strong>Resend packet 5</strong></p>
</li>
<li><p>Not whole file, only missing part</p>
</li>
</ul>
<p>This is called <strong>retransmission</strong></p>
<hr />
<p><img src="https://www.researchgate.net/publication/364434586/figure/fig2/AS%3A11431281093041375%401667090124653/Diagram-showing-the-retransmission-mechanism-used-by-TCP-when-a-packet-is-lost-or.png" alt="https://www.researchgate.net/publication/364434586/figure/fig2/AS%3A11431281093041375%401667090124653/Diagram-showing-the-retransmission-mechanism-used-by-TCP-when-a-packet-is-lost-or.png" /></p>
<hr />
<h2 id="heading-how-tcp-connection-is-closed">How TCP Connection is Closed</h2>
<p>Connection also needs proper ending.</p>
<p>TCP does <strong>not</strong> just disappear.</p>
<h3 id="heading-fin-ack-process">FIN-ACK Process</h3>
<ol>
<li><p>Client says:</p>
<blockquote>
<p>“I am done” (FIN)</p>
</blockquote>
</li>
<li><p>Server replies:</p>
<blockquote>
<p>“Okay” (ACK)</p>
</blockquote>
</li>
<li><p>Server says:</p>
<blockquote>
<p>“I am also done” (FIN)</p>
</blockquote>
</li>
<li><p>Client replies:</p>
<blockquote>
<p>“Okay” (ACK)</p>
</blockquote>
</li>
</ol>
<p>Connection closed safely.</p>
<hr />
<p><img src="https://upload.wikimedia.org/wikipedia/commons/8/8a/TCP_connection_Termination.png" alt="https://upload.wikimedia.org/wikipedia/commons/8/8a/TCP_connection_Termination.png" /></p>
<h2 id="heading-tcp-connection-life-cycle">TCP Connection Life Cycle</h2>
<ol>
<li><p><strong>Establish</strong> (3-Way Handshake)</p>
</li>
<li><p><strong>Transfer Data</strong></p>
</li>
<li><p><strong>Close Connection</strong></p>
</li>
</ol>
]]></content:encoded></item></channel></rss>