<?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 establishes a reliable connection using a SYN, SYN-ACK, and ACK exchange to ensure both client and server are ready before data transfer begins.]]></description><link>https://ashutoshblog3way.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Mon, 21 Sep 2026 22:08:08 GMT</lastBuildDate><atom:link href="https://ashutoshblog3way.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[Imagine you are trying to send a 4,000-piece jigsaw puzzle to your friend via mail. You put all the pieces in a box and ship it. But what if the box breaks? What if 40 pieces fall out? What if your friend puts the puzzle together and realizes piece #...]]></description><link>https://ashutoshblog3way.hashnode.dev/tcp-working-3-way-handshake-and-reliable-communication</link><guid isPermaLink="true">https://ashutoshblog3way.hashnode.dev/tcp-working-3-way-handshake-and-reliable-communication</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[ChaiCohort]]></category><category><![CDATA[chai-code ]]></category><category><![CDATA[chai-aur-code-web-dev-cohort-2026]]></category><category><![CDATA[ashutoshhblog]]></category><dc:creator><![CDATA[Ashutosh Kumar Awasthi]]></dc:creator><pubDate>Thu, 29 Jan 2026 18:30:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769942326537/141065c3-5d19-4535-bffd-f571d198400e.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Imagine you are trying to send a 4,000-piece jigsaw puzzle to your friend via mail. You put all the pieces in a box and ship it. But what if the box breaks? What if 40 pieces fall out? What if your friend puts the puzzle together and realizes piece #642 is missing?</p>
<p>Without rules, the internet would be just like that—broken data and missing pieces. This is exactly why we need <strong>TCP (Transmission Control Protocol)</strong>.</p>
<h3 id="heading-introduction-what-happens-if-data-is-sent-without-rules"><strong>Introduction: What happens if data is sent without rules?</strong></h3>
<p>Imagine you are sending an important message to a friend, but:</p>
<ul>
<li><p>You don’t know if they are online</p>
</li>
<li><p>You don’t know if your message reached them</p>
</li>
<li><p>You don’t know if messages arrive in the correct order</p>
</li>
</ul>
<p>That’s exactly what happens on the internet <strong>without rules</strong>.</p>
<p><em><mark>Bina rules ke data bhejna = confusion, loss, and errors.</mark></em></p>
<p>To solve this, the Internet uses <strong>TCP</strong>.</p>
<h2 id="heading-1-what-is-tcp-and-why-is-it-needed">1. What is TCP, and why is it needed?</h2>
<p><strong>TCP (Transmission Control Protocol)</strong> is a <strong>transport-layer protocol</strong> that ensures <strong>reliable communication</strong> between two systems.</p>
<p>TCP is a <strong>connection-oriented protocol.</strong> Its only job is to make sure that data sent from Point A reaches Point B exactly as it was sent—no missing bits, no corruption, and in the right order.</p>
<p><code>Important Point: Simple words: Bina rules ke internet ek kachra hota jahan files corrupt ho jati. TCP wo "Guarantee" hai jo har data packet ko sahi salamat pahunchati hai.</code></p>
<p>→ TCP makes sure that:</p>
<ul>
<li><p>Data reaches the correct destination</p>
</li>
<li><p>Data arrives in the correct order</p>
</li>
<li><p>Lost data is retransmitted</p>
</li>
</ul>
<p><em><mark>TCP ka goal simple hai: data safe aur sahi pahunchna chahiye.</mark></em></p>
<h2 id="heading-2-problems-tcp-is-designed-to-solve">2. Problems TCP is designed to solve</h2>
<p>In a wild network, three things happen constantly:</p>
<ol>
<li><p><strong>Packet Loss:</strong> A data packet gets lost in a router.</p>
</li>
<li><p><strong>Out-of-Order Delivery:</strong> Packet 3 arrives before Packet 1.</p>
</li>
<li><p><strong>Data Corruption:</strong> The data changes due to electrical interference.</p>
</li>
</ol>
<p>TCP solves all of these using "Acknowledgements" and "Sequence Numbers."</p>
<p>→ TCP exists because raw network communication has problems:</p>
<ul>
<li><p>Packets can get lost</p>
</li>
<li><p>Packets can arrive out of order</p>
</li>
<li><p>Packets can get duplicated</p>
</li>
<li><p>The receiver may get overwhelmed</p>
</li>
</ul>
<p><em><mark>TCP in sab problems ko systematically handle karta hai.</mark></em></p>
<h2 id="heading-3-what-is-the-tcp-3-way-handshake">3. What is the TCP 3-Way Handshake?</h2>
<h3 id="heading-the-famous-tcp-3-way-handshake">The Famous TCP 3-Way Handshake</h3>
<p>Before TCP sends even a single byte of data, it must establish a "trust" between the sender and receiver. This is the <strong>3-way handshake.</strong></p>
<p><strong>Think of it like a polite conversation:</strong></p>
<ol>
<li><p><strong>Step 1: SYN (Synchronise)</strong> The client says, "Hey, <em>I want to talk to you. Here is my starting sequence number (e.g., 100)."</em></p>
</li>
<li><p><strong>Step 2: SYN-ACK (Synchronise-Acknowledge)</strong> The server responds, "I <em>hear you! I'm ready too. I received your 100, so I'm expecting 101. Also, here is my starting number (e.g., 500)."</em></p>
</li>
<li><p><strong>Step 3: ACK (Acknowledge)</strong> The client says, "Got <em>it! I received your 500, so I'm expecting 501. Let's start the data transfer!"</em></p>
</li>
</ol>
<p>    <strong><em><mark>Important Point:</mark></em></strong> <em><mark> Ye bilkul ek "Hello, kya aap mujhe sun rahe ho?" wali baat hai. Jab dono taraf se 'Haan' ho jati hai, tabhi asli data transfer shuru hota hai.</mark></em></p>
<p>→ Before sending actual data, TCP first <strong>establishes a connection</strong>.</p>
<p>This connection setup is called the <strong>3-Way Handshake</strong>.</p>
<p>It is a short conversation between the <strong>client</strong> and the <strong>server</strong> to confirm:</p>
<ul>
<li><p>Both are ready</p>
</li>
<li><p>Both can send and receive data</p>
</li>
</ul>
<p><em>“Data bhejne se pehle “hello–hello” zaroori hai.”</em></p>
<h2 id="heading-4-step-by-step-working-of-syn-syn-ack-and-ack">4. Step-by-step working of SYN, SYN-ACK, and ACK</h2>
<h3 id="heading-how-data-transfer-works-reliability-and-order">How Data Transfer Works (Reliability and Order)</h3>
<p>Once the connection is established, TCP breaks your data into small segments.</p>
<ul>
<li><p><strong>Sequence Numbers:</strong> Each segment gets a number (1, 2, 3...). If they arrive out of order, the receiver uses these numbers to rearrange them.</p>
</li>
<li><p><strong>Acknowledgements (ACK):</strong> For every packet received, the receiver sends back an "ACK" (I got it!).</p>
</li>
<li><p><strong>Retransmission:</strong> If the sender doesn't get an ACK within a certain time, it assumes the packet was lost and <strong>sends it again</strong>.</p>
<p>  <strong><em>Important Point:</em></strong> <em>Agar receiver ko packet #2 nahi mila, toh wo sender ko batayega. Sender tab tak packet #2 bhejta rahega jab tak receiver "Mil gaya!" (ACK) nahi bol deta.</em></p>
</li>
</ul>
<p>→ Let’s break the handshake step by step.</p>
<h3 id="heading-step-1-syn-client-server">Step 1: SYN (Client → Server)</h3>
<p>The client sends a <strong>SYN</strong> message.</p>
<p>Meaning: “Hello Server, can we start communication?”</p>
<p>It also sends an <strong>initial sequence number</strong>.</p>
<p><em>“Client bolta hai: Main ready hoon.”</em></p>
<h3 id="heading-step-2-syn-ack-server-client">Step 2: SYN-ACK (Server → Client)</h3>
<p>The server replies with <strong>SYN-ACK</strong>.</p>
<p>Meaning: “Yes, I got your request, and I’m ready too.”</p>
<p>The server:</p>
<ul>
<li><p>Acknowledges client’s sequence number</p>
</li>
<li><p>Sends its own sequence number</p>
</li>
</ul>
<p><em>Server bolta hai: message mil gaya, main bhi ready hoon.</em></p>
<h3 id="heading-step-3-ack-client-server">Step 3: ACK (Client → Server)</h3>
<p>The client sends a final <strong>ACK</strong>.</p>
<p>Meaning: “Got it. Let’s start data transfer.”</p>
<p>At this point, the connection is <strong>established</strong>.</p>
<p><em>Ab dono side ready hain—data transfer shuru.</em></p>
<p>TCP 3-Way Handshake (Conceptual Flow): <code>Client → SYN → Server Client ← SYN-ACK ← Server Client → ACK → Server</code></p>
<p>(Connection is now <strong>open</strong>.)</p>
<h3 id="heading-closing-the-connection-the-4-way-terminate">→ Closing the Connection: The 4-Way Terminate</h3>
<p>Closing a connection is just as important as opening it. It uses <strong>FIN (Finish)</strong> and <strong>ACK</strong> flags.</p>
<ol>
<li><p><strong>Client:</strong> <em>"I'm done sending data. (FIN)"</em></p>
</li>
<li><p><strong>Server:</strong> <em>"Okay, I received your request to stop. (ACK)"</em></p>
</li>
<li><p><strong>Server:</strong> <em>(Waits a bit to finish its own tasks)</em> <em>"I'm also done. (FIN)"</em></p>
</li>
<li><p><strong>Client:</strong> <em>"Understood. Bye! (ACK)"</em></p>
</li>
</ol>
<h2 id="heading-5-how-data-transfer-works-in-tcp">5. How data transfer works in TCP</h2>
<p>Once the connection is established:</p>
<ul>
<li><p>Data is broken into segments</p>
</li>
<li><p>Each segment gets a <strong>sequence number</strong></p>
</li>
<li><p>The receiver sends <strong>ACKs</strong> for received data</p>
</li>
</ul>
<p><em>“Har data ka receipt milta hai.”</em></p>
<h2 id="heading-sequence-numbers-and-acknowledgements-high-level">→ Sequence numbers and acknowledgements (High level)</h2>
<ul>
<li><p><strong>The sequence number</strong> tells the position of the data</p>
</li>
<li><p><strong>ACK number</strong> confirms how much data is received</p>
</li>
</ul>
<p>If data is missing:</p>
<ul>
<li><p>The receiver does not ACK</p>
</li>
<li><p>Sender retransmits</p>
</li>
</ul>
<p><em>“Jo nahi mila, woh dubara bhejo.”</em></p>
<h2 id="heading-6-how-tcp-ensures-reliability-order-and-correctness">6. How TCP ensures reliability, order, and correctness</h2>
<p>TCP guarantees reliability using:</p>
<h3 id="heading-1-acknowledgements">1. Acknowledgements</h3>
<p>The receiver confirms receipt of data.</p>
<h3 id="heading-2-retransmission">2. Retransmission</h3>
<p>Lost packets are sent again.</p>
<h3 id="heading-3-ordered-delivery">3. Ordered delivery</h3>
<p>Data is rearranged before delivery to the application.</p>
<h3 id="heading-4-flow-control">4. Flow control</h3>
<p>The sender does not overwhelm the receiver.</p>
<p><em><mark>“TCP ensures data is complete, ordered, and correct.”</mark></em></p>
<h2 id="heading-how-tcp-handles-packet-loss">→ How TCP handles packet loss</h2>
<p>If a packet is lost:</p>
<ul>
<li><p>ACK is not received</p>
</li>
<li><p>Timer expires</p>
</li>
<li><p>The sender retransmits the missing packet</p>
</li>
</ul>
<p><em><mark>“Packet loss = retry, not failure.”</mark></em></p>
<h2 id="heading-7-how-a-tcp-connection-is-closed">7. How a TCP connection is closed</h2>
<p>Closing a TCP connection is also controlled and graceful.</p>
<h3 id="heading-step-1-fin-one-side-wants-to-close">Step 1: FIN (One side wants to close)</h3>
<p>“I have no more data to send.”</p>
<h3 id="heading-step-2-ack-the-other-side-confirms">Step 2: ACK (The other side confirms)</h3>
<p>“Got it.”</p>
<h3 id="heading-step-3-fin-the-other-side-also-finishes">Step 3: FIN (The other side also finishes)</h3>
<p>“I’m done too.”</p>
<h3 id="heading-step-4-ack-final-confirmation">Step 4: ACK (Final confirmation)</h3>
<p>The connection is now <strong>closed</strong>.</p>
<p>“<em>TCP goodbye bhi politely bolta hai.”</em></p>
<p>TCP connection lifecycle (big picture):</p>
<p><code>Connection Establishment (3-Way Handshake)</code></p>
<p><code>↓</code></p>
<p><code>Reliable Data Transfer</code></p>
<p><code>↓</code></p>
<p><code>Graceful Connection Termination</code></p>
<p><strong><em><mark>TCP may look complex at first, but its logic is simple: Agar data important hai, TCP mandatory hai.</mark></em></strong></p>
<p><code>TCP uses a 3-way handshake to establish trust, sequence numbers and acknowledgements to ensure reliable data transfer, and a controlled termination process to close connections safely.</code></p>
<p>let’s connect on LinkedIn: <a target="_blank" href="https://linkedin.com/in/ashutoshkawasthii"><strong>→ LinkedIn</strong></a><code> </code></p>
]]></content:encoded></item></channel></rss>