<?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]]></title><description><![CDATA[TCP Working]]></description><link>https://tcpworkingblogbyshivamkumar.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sat, 12 Sep 2026 02:58:18 GMT</lastBuildDate><atom:link href="https://tcpworkingblogbyshivamkumar.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 (Beginner Guide)]]></title><description><![CDATA[🤔 First Question: What Happens If Data Is Sent Without Rules?
Imagine you want to send a long message to your friend using WhatsApp.
But:

messages arrive in random order

some messages are missing

some messages are repeated


Would you understand ...]]></description><link>https://tcpworkingblogbyshivamkumar.hashnode.dev/tcp-working-3-way-handshake-and-reliable-communication-beginner-guide</link><guid isPermaLink="true">https://tcpworkingblogbyshivamkumar.hashnode.dev/tcp-working-3-way-handshake-and-reliable-communication-beginner-guide</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[ChaiCohort]]></category><category><![CDATA[TCP]]></category><category><![CDATA[TCP Handshake]]></category><category><![CDATA[interview]]></category><dc:creator><![CDATA[Shivam Kumar]]></dc:creator><pubDate>Sat, 31 Jan 2026 04:59:59 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769835487339/cfd388e7-4a30-414e-9ec9-77195f2bd1de.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-first-question-what-happens-if-data-is-sent-without-rules">🤔 First Question: What Happens If Data Is Sent Without Rules?</h2>
<p>Imagine you want to send a <strong>long message</strong> to your friend using WhatsApp.</p>
<p>But:</p>
<ul>
<li><p>messages arrive in random order</p>
</li>
<li><p>some messages are missing</p>
</li>
<li><p>some messages are repeated</p>
</li>
</ul>
<p>Would you understand the message? ❌<br />No.</p>
<p>This is exactly the problem computers face when sending data on the internet.</p>
<p>👉 <strong>Data needs rules</strong>.</p>
<hr />
<h2 id="heading-why-rules-are-needed-on-the-internet">🌍 Why Rules Are Needed on the Internet</h2>
<p>The internet:</p>
<ul>
<li><p>is very fast</p>
</li>
<li><p>is shared by millions</p>
</li>
<li><p>can lose data</p>
</li>
<li><p>can deliver data out of order</p>
</li>
</ul>
<p>So computers need a <strong>reliable way</strong> to talk.</p>
<p>That reliable system is called <strong>TCP</strong>.</p>
<hr />
<h2 id="heading-what-is-tcp">📦 What is TCP?</h2>
<p><strong>TCP = Transmission Control Protocol</strong></p>
<blockquote>
<p><strong>TCP is a set of rules that makes sure data is sent correctly, completely, and in order.</strong></p>
</blockquote>
<hr />
<h3 id="heading-one-line-definition">🧠 One-Line Definition</h3>
<blockquote>
<p><strong>TCP makes sure “data reaches safely and properly.”</strong></p>
</blockquote>
<hr />
<h2 id="heading-why-tcp-is-needed-problems-it-solves">❓ Why TCP Is Needed (Problems It Solves)</h2>
<p>Without TCP:</p>
<ul>
<li><p>data may be lost</p>
</li>
<li><p>data may arrive in wrong order</p>
</li>
<li><p>sender won’t know if receiver got data</p>
</li>
<li><p>communication becomes unreliable</p>
</li>
</ul>
<p>TCP solves:<br />✅ Reliability<br />✅ Correct order<br />✅ No missing data<br />✅ Error handling</p>
<hr />
<h2 id="heading-big-picture-tcp-communication-flow">🧭 Big Picture: TCP Communication Flow</h2>
<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>
<p><img src="https://miro.medium.com/1%2AXwSot0zFwvX_8M8wIoJjIg.png" alt="https://miro.medium.com/1%2AXwSot0zFwvX_8M8wIoJjIg.png" /></p>
<p>TCP has <strong>3 main phases</strong>:</p>
<ol>
<li><p>Connection setup</p>
</li>
<li><p>Data transfer</p>
</li>
<li><p>Connection close</p>
</li>
</ol>
<p>Let’s understand <strong>each slowly</strong>.</p>
<hr />
<h2 id="heading-what-is-tcp-3-way-handshake">🤝 What is TCP 3-Way Handshake?</h2>
<p>Before sending data, TCP first asks:</p>
<blockquote>
<p>“Are you ready to talk?”</p>
</blockquote>
<p>This is called the <strong>3-Way Handshake</strong>.</p>
<hr />
<h3 id="heading-simple-conversation-analogy">🗣️ Simple Conversation Analogy</h3>
<p>Imagine this conversation:</p>
<ul>
<li><p>Client: “Can I talk to you?”</p>
</li>
<li><p>Server: “Yes, I can hear you. Can you hear me?”</p>
</li>
<li><p>Client: “Yes, I can hear you.”</p>
</li>
</ul>
<p>Now conversation starts 😊</p>
<p>Same idea in TCP.</p>
<hr />
<h2 id="heading-tcp-3-way-handshake-step-by-step">🔁 TCP 3-Way Handshake (Step by Step)</h2>
<p><img src="https://static.afteracademy.com/images/what-is-a-tcp-3-way-handshake-process-three-way-handshaking-terminating-connection-6ea4a4c72d165361.jpg" alt="https://static.afteracademy.com/images/what-is-a-tcp-3-way-handshake-process-three-way-handshaking-terminating-connection-6ea4a4c72d165361.jpg" /></p>
<p><img src="https://www.flamingbytes.com/images/tcp-handshake-1.png" alt="https://www.flamingbytes.com/images/tcp-handshake-1.png" /></p>
<hr />
<h3 id="heading-step-1-syn-client-server">🟢 Step 1: SYN (Client → Server)</h3>
<p>Client says:</p>
<blockquote>
<p>“I want to start a connection”</p>
</blockquote>
<p>This message is called <strong>SYN</strong> (synchronize).</p>
<p>📌 Means: <em>“Let’s talk”</em></p>
<hr />
<h3 id="heading-step-2-syn-ack-server-client">🟢 Step 2: SYN-ACK (Server → Client)</h3>
<p>Server replies:</p>
<blockquote>
<p>“I received your request. I am ready too.”</p>
</blockquote>
<p>This is <strong>SYN + ACK</strong>.</p>
<p>📌 Means:</p>
<ul>
<li><p>I heard you (ACK)</p>
</li>
<li><p>I want to talk too (SYN)</p>
</li>
</ul>
<hr />
<h3 id="heading-step-3-ack-client-server">🟢 Step 3: ACK (Client → Server)</h3>
<p>Client replies:</p>
<blockquote>
<p>“Yes, I heard you too.”</p>
</blockquote>
<p>This is <strong>ACK</strong>.</p>
<p>🎉 Connection is now established.</p>
<hr />
<h2 id="heading-after-3-way-handshake">✅ After 3-Way Handshake</h2>
<p>Now both sides:</p>
<ul>
<li><p>know each other</p>
</li>
<li><p>are ready</p>
</li>
<li><p>can start data transfer</p>
</li>
</ul>
<p>📌 <strong>No data is sent before handshake completes</strong>.</p>
<hr />
<h2 id="heading-how-data-transfer-works-in-tcp">📤 How Data Transfer Works in TCP</h2>
<p>After connection is established:</p>
<ul>
<li><p>data is broken into small packets</p>
</li>
<li><p>packets are numbered</p>
</li>
<li><p>receiver confirms each packet</p>
</li>
</ul>
<hr />
<h2 id="heading-sequence-numbers-very-high-level">🔢 Sequence Numbers (Very High Level)</h2>
<p>Think of sending pages of a book 📖</p>
<ul>
<li><p>Page 1</p>
</li>
<li><p>Page 2</p>
</li>
<li><p>Page 3</p>
</li>
</ul>
<p>TCP adds <strong>numbers</strong> so receiver knows:</p>
<ul>
<li><p>correct order</p>
</li>
<li><p>if something is missing</p>
</li>
</ul>
<hr />
<h2 id="heading-acknowledgements-ack">✅ Acknowledgements (ACK)</h2>
<p>After receiving data:</p>
<ul>
<li><p>receiver sends <strong>ACK</strong></p>
</li>
<li><p>sender knows data arrived safely</p>
</li>
</ul>
<p><img src="https://static.wixstatic.com/media/a2409e_aef337e8e53946f383f37bad39fe1028~mv2.jpg/v1/fill/w_566%2Ch_480%2Cal_c%2Clg_1%2Cq_80/a2409e_aef337e8e53946f383f37bad39fe1028~mv2.jpg" alt="https://static.wixstatic.com/media/a2409e_aef337e8e53946f383f37bad39fe1028~mv2.jpg/v1/fill/w_566%2Ch_480%2Cal_c%2Clg_1%2Cq_80/a2409e_aef337e8e53946f383f37bad39fe1028~mv2.jpg" /></p>
<p><img src="https://intronetworks.cs.luc.edu/current/uhtml/_images/tcp_ladder_states.svg" alt="https://intronetworks.cs.luc.edu/current/uhtml/_images/tcp_ladder_states.svg" /></p>
<hr />
<h2 id="heading-what-if-data-is-lost">❌ What If Data Is Lost?</h2>
<p>This happens often on the internet.</p>
<p>TCP handles it automatically.</p>
<hr />
<h3 id="heading-packet-loss-amp-retransmission">🔁 Packet Loss &amp; Retransmission</h3>
<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://book.systemsapproach.org/_images/f05-10-9780123850591.png" alt="https://book.systemsapproach.org/_images/f05-10-9780123850591.png" /></p>
<p>If:</p>
<ul>
<li>packet 3 is missing</li>
</ul>
<p>Then:</p>
<ul>
<li><p>receiver does not send ACK for packet 3</p>
</li>
<li><p>sender resends packet 3</p>
</li>
</ul>
<p>📌 User never notices this.</p>
<hr />
<h2 id="heading-how-tcp-ensures-reliability">🛡️ How TCP Ensures Reliability</h2>
<p>TCP ensures:</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Feature</td><td>How</td></tr>
</thead>
<tbody>
<tr>
<td>Reliability</td><td>ACK + retransmission</td></tr>
<tr>
<td>Correct order</td><td>Sequence numbers</td></tr>
<tr>
<td>No duplication</td><td>Tracking packets</td></tr>
<tr>
<td>Error detection</td><td>Checksums</td></tr>
</tbody>
</table>
</div><hr />
<h2 id="heading-how-tcp-connection-is-closed">🔚 How TCP Connection Is Closed</h2>
<p>When communication is done, TCP <strong>closes properly</strong>.</p>
<hr />
<h3 id="heading-tcp-connection-termination-simple">👋 TCP Connection Termination (Simple)</h3>
<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.excentis.com/web/image/122886-2cd58847/tekening_website_blog.webp?access_token=ecea94ef-81de-4cf4-93a0-58e365abdb55" alt="https://www.excentis.com/web/image/122886-2cd58847/tekening_website_blog.webp?access_token=ecea94ef-81de-4cf4-93a0-58e365abdb55" /></p>
<p>Steps:</p>
<ol>
<li><p>One side sends <strong>FIN</strong> (I am done)</p>
</li>
<li><p>Other side sends <strong>ACK</strong></p>
</li>
<li><p>Other side sends <strong>FIN</strong></p>
</li>
<li><p>First side sends <strong>ACK</strong></p>
</li>
</ol>
<p>Connection closed cleanly ✅</p>
<hr />
<h2 id="heading-complete-tcp-lifecycle">🔄 Complete TCP Lifecycle</h2>
<p><img src="https://miro.medium.com/1%2AXwSot0zFwvX_8M8wIoJjIg.png" alt="https://miro.medium.com/1%2AXwSot0zFwvX_8M8wIoJjIg.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>
<pre><code class="lang-plaintext">Handshake → Data Transfer → Close
</code></pre>
<hr />
<h2 id="heading-why-tcp-is-important-for-web-developers">🧠 Why TCP Is Important for Web Developers</h2>
<p>TCP is used by:</p>
<ul>
<li><p>HTTP / HTTPS</p>
</li>
<li><p>Browsers</p>
</li>
<li><p>APIs</p>
</li>
<li><p>Databases</p>
</li>
<li><p>Backend servers</p>
</li>
</ul>
<p>If TCP fails → website fails.</p>
<hr />
<h2 id="heading-final-thoughts">🏁 Final Thoughts</h2>
<p>If TCP felt complex before — now it shouldn’t.</p>
<p>Just remember:</p>
<ul>
<li><p>TCP talks <strong>before sending</strong></p>
</li>
<li><p>TCP checks <strong>after sending</strong></p>
</li>
<li><p>TCP fixes <strong>if something breaks</strong></p>
</li>
</ul>
<p>TCP = <strong>safe &amp; reliable conversation</strong>.</p>
<hr />
<h2 id="heading-what-you-should-remember">🚀 What You Should Remember</h2>
<ul>
<li><p>TCP needs handshake</p>
</li>
<li><p>TCP sends data carefully</p>
</li>
<li><p>TCP ensures nothing is lost</p>
</li>
<li><p>TCP closes properly</p>
</li>
</ul>
<p>Once this is clear,<br /><strong>Networking becomes logical, not scary</strong> 💙</p>
]]></content:encoded></item></channel></rss>