<?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[TCPWorking]]></title><description><![CDATA[TCPWorking]]></description><link>https://tcpworkingwithmrunali.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Mon, 07 Sep 2026 07:32:24 GMT</lastBuildDate><atom:link href="https://tcpworkingwithmrunali.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 happens if data is sent without rules?
Imagine sending a long WhatsApp message, but:

Messages arrive out of order

Some messages never arrive

Some messages arrive twice

You don’t know if the other person even received them


That’s what sendi...]]></description><link>https://tcpworkingwithmrunali.hashnode.dev/tcp-working-3-way-handshake-and-reliable-communication</link><guid isPermaLink="true">https://tcpworkingwithmrunali.hashnode.dev/tcp-working-3-way-handshake-and-reliable-communication</guid><category><![CDATA[TCP]]></category><category><![CDATA[TCP Handshake]]></category><dc:creator><![CDATA[Mrunali Udata]]></dc:creator><pubDate>Sun, 01 Feb 2026 14:48:15 GMT</pubDate><content:encoded><![CDATA[<h2 id="heading-what-happens-if-data-is-sent-without-rules">What happens if data is sent <strong>without rules</strong>?</h2>
<p>Imagine sending a long WhatsApp message, but:</p>
<ul>
<li><p>Messages arrive <strong>out of order</strong></p>
</li>
<li><p>Some messages <strong>never arrive</strong></p>
</li>
<li><p>Some messages arrive <strong>twice</strong></p>
</li>
<li><p>You don’t know if the other person even received them</p>
</li>
</ul>
<p>That’s what sending data <strong>without rules</strong> looks like on a network.</p>
<p>The internet breaks data into <strong>small packets</strong>, and those packets:</p>
<ul>
<li><p>Can take <strong>different paths</strong></p>
</li>
<li><p>Can get <strong>lost</strong></p>
</li>
<li><p>Can arrive <strong>out of order</strong></p>
</li>
</ul>
<p>👉 We need rules to make communication <strong>reliable</strong>.</p>
<hr />
<h2 id="heading-what-is-tcp-and-why-is-it-needed">What is TCP and why is it needed?</h2>
<p><strong>TCP (Transmission Control Protocol)</strong> is a communication rulebook that ensures:</p>
<ul>
<li><p>Data is <strong>delivered</strong></p>
</li>
<li><p>Data is <strong>delivered in order</strong></p>
</li>
<li><p>Data is <strong>delivered correctly</strong></p>
</li>
<li><p>Sender and receiver <strong>agree</strong> before talking</p>
</li>
</ul>
<p>💡 TCP is used when <strong>accuracy matters more than speed</strong>.</p>
<p>Examples:</p>
<ul>
<li><p>Websites (HTTP/HTTPS)</p>
</li>
<li><p>File downloads</p>
</li>
<li><p>Emails</p>
</li>
<li><p>Login systems</p>
</li>
<li><p>APIs</p>
</li>
</ul>
<hr />
<h2 id="heading-problems-tcp-is-designed-to-solve">Problems TCP is designed to solve</h2>
<p>TCP exists to fix these real-world network problems:</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Problem</td><td>What TCP Does</td></tr>
</thead>
<tbody>
<tr>
<td>Data loss</td><td>Retransmits missing data</td></tr>
<tr>
<td>Out-of-order packets</td><td>Reorders them correctly</td></tr>
<tr>
<td>Duplicate packets</td><td>Detects and removes duplicates</td></tr>
<tr>
<td>Unknown delivery status</td><td>Uses acknowledgements</td></tr>
<tr>
<td>Network congestion</td><td>Slows down sending speed</td></tr>
</tbody>
</table>
</div><hr />
<h2 id="heading-what-is-the-tcp-3-way-handshake">What is the TCP 3-Way Handshake?</h2>
<p>Before sending data, TCP <strong>establishes a connection</strong>.</p>
<p>Think of it like starting a phone call ☎️:</p>
<blockquote>
<p>“Can you hear me?”<br />“Yes, I can hear you.”<br />“Great, let’s talk.”</p>
</blockquote>
<p>This agreement is called the <strong>3-Way Handshake</strong>.</p>
<hr />
<h2 id="heading-step-by-step-syn-syn-ack-ack">Step-by-step: SYN, SYN-ACK, ACK</h2>
<h3 id="heading-step-1-syn-client-server">Step 1: SYN (Client → Server)</h3>
<p>Client says:</p>
<blockquote>
<p>“Hey Server, I want to talk. Are you available?”</p>
</blockquote>
<ul>
<li><p>Client sends a <strong>SYN</strong> packet</p>
</li>
<li><p>Includes a <strong>sequence number</strong> (starting point)</p>
</li>
</ul>
<hr />
<h3 id="heading-step-2-syn-ack-server-client">Step 2: SYN-ACK (Server → Client)</h3>
<p>Server replies:</p>
<blockquote>
<p>“Yes, I’m available. I hear you.”</p>
</blockquote>
<ul>
<li><p>Server sends <strong>SYN + ACK</strong></p>
</li>
<li><p>ACK confirms client’s SYN</p>
</li>
<li><p>SYN includes server’s own sequence number</p>
</li>
</ul>
<hr />
<h3 id="heading-step-3-ack-client-server">🧩 Step 3: ACK (Client → Server)</h3>
<p>Client responds:</p>
<blockquote>
<p>“Great, I hear you too.”</p>
</blockquote>
<ul>
<li><p>Client sends <strong>ACK</strong></p>
</li>
<li><p>Connection is now <strong>established</strong></p>
</li>
</ul>
<p>🎉 Both sides agree → <strong>data transfer can begin</strong></p>
<p><img src="https://static.afteracademy.com/images/what-is-a-tcp-3-way-handshake-process-three-way-handshaking-establishing-connection-6a724e77ba96e241.jpg" alt="https://static.afteracademy.com/images/what-is-a-tcp-3-way-handshake-process-three-way-handshaking-establishing-connection-6a724e77ba96e241.jpg" /></p>
<p><img src="https://miro.medium.com/0%2AWcbPv9sWlCl6RV4a" alt="https://miro.medium.com/0%2AWcbPv9sWlCl6RV4a" /></p>
<hr />
<h2 id="heading-how-data-transfer-works-in-tcp">How data transfer works in TCP</h2>
<p>Once connected:</p>
<ul>
<li><p>Data is split into <strong>segments</strong></p>
</li>
<li><p>Each segment has:</p>
<ul>
<li><p><strong>Sequence number</strong></p>
</li>
<li><p><strong>Data</strong></p>
</li>
</ul>
</li>
<li><p>Receiver sends back <strong>ACKs</strong></p>
</li>
</ul>
<p>Example:</p>
<ul>
<li><p>Sender sends data #1</p>
</li>
<li><p>Receiver replies: “ACK 2” (means “I got #1, send next”)</p>
</li>
</ul>
<p>This continues until all data is sent.</p>
<hr />
<h2 id="heading-sequence-numbers-amp-acknowledgements-high-level">Sequence numbers &amp; acknowledgements (high level)</h2>
<p>Think of <strong>page numbers in a book</strong> 📖</p>
<ul>
<li><p>Sequence number = page number</p>
</li>
<li><p>ACK = “I’ve read up to page X”</p>
</li>
</ul>
<p>If page 5 is missing:</p>
<ul>
<li><p>Receiver keeps asking for page 5</p>
</li>
<li><p>Sender resends page 5</p>
</li>
</ul>
<hr />
<h2 id="heading-how-tcp-ensures-reliability-order-amp-correctness">How TCP ensures reliability, order &amp; correctness</h2>
<p>TCP guarantees:</p>
<h3 id="heading-reliability">Reliability</h3>
<ul>
<li><p>Uses <strong>ACKs</strong></p>
</li>
<li><p>Retransmits missing data</p>
</li>
</ul>
<h3 id="heading-correct-order">Correct order</h3>
<ul>
<li><p>Uses <strong>sequence numbers</strong></p>
</li>
<li><p>Reorders packets before delivering to app</p>
</li>
</ul>
<h3 id="heading-correctness">Correctness</h3>
<ul>
<li><p>Uses <strong>checksums</strong></p>
</li>
<li><p>Detects corrupted data</p>
</li>
</ul>
<h3 id="heading-flow-amp-congestion-control">Flow &amp; congestion control</h3>
<ul>
<li>Adjusts speed based on network conditions</li>
</ul>
<hr />
<h2 id="heading-what-if-a-packet-is-lost">What if a packet is lost?</h2>
<p>Example:</p>
<ul>
<li><p>Sender sends packets 1, 2, 3</p>
</li>
<li><p>Packet 2 is lost ❌</p>
</li>
<li><p>Receiver says: “I’m missing packet 2”</p>
</li>
<li><p>Sender <strong>retransmits packet 2</strong></p>
</li>
</ul>
<p>No guessing. No confusion. Just rules.</p>
<p><img src="https://www.researchgate.net/publication/382092781/figure/fig1/AS%3A11431281259508197%401720533616113/TCP-packet-loss-detection-and-retransmission-triggered-by-a-timeout-or-by-three-duplicate.ppm" alt="https://www.researchgate.net/publication/382092781/figure/fig1/AS%3A11431281259508197%401720533616113/TCP-packet-loss-detection-and-retransmission-triggered-by-a-timeout-or-by-three-duplicate.ppm" /></p>
<p><img src="https://assets.extrahop.com/images/infographics/TCP-RTO-Retransmission-Timeout-Diagram.jpg" alt="https://assets.extrahop.com/images/infographics/TCP-RTO-Retransmission-Timeout-Diagram.jpg" /></p>
<hr />
<h2 id="heading-how-a-tcp-connection-is-closed-fin-amp-ack">How a TCP connection is closed (FIN &amp; ACK)</h2>
<p>Ending a TCP connection is also <strong>polite and structured</strong>.</p>
<h3 id="heading-step-by-step">Step-by-step:</h3>
<ol>
<li><p>Client sends <strong>FIN</strong> → “I’m done sending”</p>
</li>
<li><p>Server sends <strong>ACK</strong></p>
</li>
<li><p>Server sends <strong>FIN</strong> → “I’m done too”</p>
</li>
<li><p>Client sends <strong>ACK</strong></p>
</li>
</ol>
<p>Connection is <strong>cleanly closed</strong>.</p>
<p><img src="https://images.openai.com/static-rsc-1/y6MM7b1qn0yE9aTpXoGuRZVTMNJy40Uj8YSkZCzLX4DCrHauBq29EcHm_Yrtv9CgBRjyNnwiyyCO6PtL-Ph-XolHrLoY7nJMcsZrL4wfa_wQxm3PsA4Gzp3SQ_WVVLWPrQiDcXhy-sK5pdIgJTU6Dw" alt="https://www.tcpipguide.com/free/diagrams/tcpclose.png" /></p>
<p><img src="https://www.ibm.com/support/pages/system/files/inline-images/Flow%20chart%20TCP%20connection_0.jpg" alt="https://www.ibm.com/support/pages/system/files/inline-images/Flow%20chart%20TCP%20connection_0.jpg" /></p>
<hr />
<h2 id="heading-tcp-connection-lifecycle-big-picture">TCP Connection Lifecycle (big picture)</h2>
<pre><code class="lang-plaintext">ESTABLISH
   ↓
3-Way Handshake
   ↓
DATA TRANSFER
   ↓
ACKs &amp; Retransmissions
   ↓
CONNECTION CLOSE
</code></pre>
]]></content:encoded></item></channel></rss>