<?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://3-way-handshake-for-beginner.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Thu, 24 Sep 2026 08:55:34 GMT</lastBuildDate><atom:link href="https://3-way-handshake-for-beginner.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[What is TCP? (In simple words)
TCP (Transmission Control Protocol) is a set of rules that makes sure:

Data reaches the right destination

Data arrives completely

Data arrives in the correct order

Lost data is sent again

Both sides agree when comm...]]></description><link>https://3-way-handshake-for-beginner.hashnode.dev/tcp-working-3-way-handshake-and-reliable-communication</link><guid isPermaLink="true">https://3-way-handshake-for-beginner.hashnode.dev/tcp-working-3-way-handshake-and-reliable-communication</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[networking]]></category><category><![CDATA[3-way handshake]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Samir Maharana]]></dc:creator><pubDate>Thu, 29 Jan 2026 19:01:20 GMT</pubDate><content:encoded><![CDATA[<h2 id="heading-what-is-tcp-in-simple-words">What is TCP? (In simple words)</h2>
<p><strong>TCP (Transmission Control Protocol)</strong> is a set of rules that makes sure:</p>
<ul>
<li><p>Data reaches the <strong>right destination</strong></p>
</li>
<li><p>Data arrives <strong>completely</strong></p>
</li>
<li><p>Data arrives in the <strong>correct order</strong></p>
</li>
<li><p>Lost data is <strong>sent again</strong></p>
</li>
<li><p>Both sides agree when communication <strong>starts and ends</strong></p>
</li>
</ul>
<p>💡 TCP is used when <strong>accuracy matters</strong>:</p>
<ul>
<li><p>Websites (HTTP/HTTPS)</p>
</li>
<li><p>Emails</p>
</li>
<li><p>File downloads</p>
</li>
<li><p>Login systems</p>
</li>
</ul>
<p>If data loss is okay (like live video), TCP is usually <strong>not</strong> used.</p>
<h2 id="heading-problems-tcp-is-designed-to-solve">Problems TCP is designed to solve</h2>
<p>Without TCP, these problems happen:</p>
<ol>
<li><p>Data may be <strong>lost</strong></p>
</li>
<li><p>Data may arrive <strong>out of order</strong></p>
</li>
<li><p>Receiver may get <strong>duplicate data</strong></p>
</li>
<li><p>Sender doesn’t know if data was received</p>
</li>
<li><p>No clear start or end of communication</p>
</li>
</ol>
<p>TCP fixes <strong>all of these</strong>.</p>
<h2 id="heading-before-tcp-sends-data-the-3-way-handshake">Before TCP sends data: the 3-Way Handshake</h2>
<p>TCP <strong>never sends data blindly</strong>.</p>
<p>First, it checks:</p>
<blockquote>
<p>“Are you ready to talk?”<br />“Yes, I’m ready.”<br />“Cool, let’s talk.”</p>
</blockquote>
<p>This process is called the <strong>TCP 3-Way Handshake</strong>.</p>
<h2 id="heading-tcp-3-way-handshake-conversation-analogy">TCP 3-Way Handshake (Conversation Analogy)</h2>
<h3 id="heading-step-1-syn-can-we-talk">Step 1: SYN — “Can we talk?”</h3>
<p>Client → Server</p>
<p>Client says:</p>
<blockquote>
<p>“Hey Server, I want to start a connection.”</p>
</blockquote>
<p>This message is called <strong>SYN</strong> (Synchronize).</p>
<h3 id="heading-step-2-syn-ack-yes-im-listening">Step 2: SYN-ACK — “Yes, I’m listening”</h3>
<p>Server → Client</p>
<p>Server replies:</p>
<blockquote>
<p>“Yes, I got your request, and I’m ready too.”</p>
</blockquote>
<p>This message is <strong>SYN + ACK</strong><br />(Synchronize + Acknowledge)</p>
<h3 id="heading-step-3-ack-great-lets-start">Step 3: ACK — “Great, let’s start”</h3>
<p>Client → Server</p>
<p>Client confirms:</p>
<blockquote>
<p>“Got it. Let’s begin communication.”</p>
</blockquote>
<p>This is <strong>ACK</strong> (Acknowledge).</p>
<p>✅ <strong>Connection established</strong><br />Now data transfer can begin.</p>
<h2 id="heading-why-3-steps-why-not-just-1">Why 3 steps? Why not just 1?</h2>
<p>Because both sides must confirm:</p>
<ul>
<li><p>They are <strong>alive</strong></p>
</li>
<li><p>They can <strong>send</strong></p>
</li>
<li><p>They can <strong>receive</strong></p>
</li>
</ul>
<p>Skipping this can cause:</p>
<ul>
<li><p>Fake connections</p>
</li>
<li><p>Half-open connections</p>
</li>
<li><p>Wasted resources</p>
</li>
</ul>
<h2 id="heading-how-data-transfer-works-in-tcp-simple-version">How data transfer works in TCP (simple version)</h2>
<p>Once the connection is open:</p>
<ul>
<li><p>Data is broken into <strong>small chunks</strong></p>
</li>
<li><p>Each chunk is given a <strong>sequence number</strong></p>
</li>
<li><p>Receiver sends back <strong>ACKs</strong> saying what it received</p>
</li>
</ul>
<p>Think of sequence numbers like <strong>page numbers in a book</strong>.</p>
<h2 id="heading-sequence-numbers-amp-acks-high-level">Sequence Numbers &amp; ACKs (High-level)</h2>
<p>Let’s say you send data:</p>
<ul>
<li><p>Packet 1 → Sequence 1</p>
</li>
<li><p>Packet 2 → Sequence 2</p>
</li>
<li><p>Packet 3 → Sequence 3</p>
</li>
</ul>
<p>Receiver replies:</p>
<blockquote>
<p>“I got up to Sequence 3.”</p>
</blockquote>
<p>That reply is an <strong>ACK</strong>.</p>
<p>If Packet 2 is missing:</p>
<ul>
<li><p>Receiver says:</p>
<blockquote>
<p>“I’m still waiting for Sequence 2.”</p>
</blockquote>
</li>
</ul>
<h2 id="heading-how-tcp-ensures-reliability">How TCP ensures reliability</h2>
<p>TCP uses <strong>four main techniques</strong>:</p>
<h3 id="heading-1-sequence-numbers">1. Sequence Numbers</h3>
<ul>
<li><p>Keeps data <strong>in order</strong></p>
</li>
<li><p>Helps detect missing data</p>
</li>
</ul>
<h3 id="heading-2-acknowledgements-acks">2. Acknowledgements (ACKs)</h3>
<ul>
<li><p>Receiver confirms what it received</p>
</li>
<li><p>Sender knows what was successful</p>
</li>
</ul>
<h3 id="heading-3-retransmission">3. Retransmission</h3>
<p>If a packet is lost:</p>
<ul>
<li><p>ACK doesn’t arrive</p>
</li>
<li><p>Sender waits for a timeout</p>
</li>
<li><p>Sender <strong>resends</strong> the missing packet</p>
</li>
</ul>
<h3 id="heading-4-error-checking">4. Error Checking</h3>
<ul>
<li><p>Each packet has a <strong>checksum</strong></p>
</li>
<li><p>If data is corrupted, it’s discarded</p>
</li>
<li><p>Sender resends it</p>
</li>
</ul>
<h2 id="heading-what-if-a-packet-is-lost-real-example">What if a packet is lost? (Real example)</h2>
<ol>
<li><p>Sender sends packets 1, 2, 3</p>
</li>
<li><p>Packet 2 gets lost</p>
</li>
<li><p>Receiver gets 1 and 3</p>
</li>
<li><p>Receiver says:</p>
<blockquote>
<p>“I got 1, still waiting for 2”</p>
</blockquote>
</li>
<li><p>Sender resends packet 2</p>
</li>
<li><p>Communication continues normally</p>
</li>
</ol>
<p>No panic. No confusion.<br />That’s TCP doing its job.</p>
<h2 id="heading-how-tcp-connection-is-closed">How TCP connection is closed</h2>
<p>TCP also closes connections <strong>politely</strong>, not suddenly.</p>
<h3 id="heading-connection-termination-uses">Connection termination uses:</h3>
<ul>
<li><p><strong>FIN</strong> (Finish)</p>
</li>
<li><p><strong>ACK</strong> (Acknowledge)</p>
</li>
</ul>
<h3 id="heading-simple-flow">Simple flow:</h3>
<ol>
<li><p>Client → Server: <strong>FIN</strong></p>
<blockquote>
<p>“I’m done sending data.”</p>
</blockquote>
</li>
<li><p>Server → Client: <strong>ACK</strong></p>
<blockquote>
<p>“Okay, I got that.”</p>
</blockquote>
</li>
<li><p>Server → Client: <strong>FIN</strong></p>
<blockquote>
<p>“I’m done too.”</p>
</blockquote>
</li>
<li><p>Client → Server: <strong>ACK</strong></p>
<blockquote>
<p>“Confirmed. Bye.”</p>
</blockquote>
</li>
</ol>
<p>🔚 Connection closed safely.</p>
<h2 id="heading-why-proper-closing-matters">Why proper closing matters</h2>
<p>If connections aren’t closed properly:</p>
<ul>
<li><p>Memory leaks</p>
</li>
<li><p>Too many open connections</p>
</li>
<li><p>Server crashes over time</p>
</li>
</ul>
<p>TCP avoids this.</p>
<h2 id="heading-tcp-connection-lifecycle-big-picture">TCP Connection Lifecycle (big picture)</h2>
<ol>
<li><p><strong>Establish connection</strong><br /> → 3-Way Handshake</p>
</li>
<li><p><strong>Data transfer</strong><br /> → Sequence numbers, ACKs, retransmissions</p>
</li>
<li><p><strong>Close connection</strong><br /> → FIN &amp; ACK</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769713045973/d6ac5fa3-6856-4b88-902e-3e1444f9b861.png" alt class="image--center mx-auto" /></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769713163738/065ccc69-2e1e-4021-ae8c-3d13cbdb5e35.png" alt class="image--center mx-auto" /></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769713237162/4ca056b3-46f4-4903-b947-96a21f83da1c.png" alt class="image--center mx-auto" /></p>
</li>
</ol>
]]></content:encoded></item></channel></rss>