<?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 and 3-Way Handshake]]></title><description><![CDATA[TCP Working and 3-Way Handshake]]></description><link>https://tcp-working-by-rahul.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Mon, 21 Sep 2026 08:08:26 GMT</lastBuildDate><atom:link href="https://tcp-working-by-rahul.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 and Why is it Needed?
When you send data, routers along the way might get overwhelmed and drop your packets, or they might take different paths and arrive out of order.
TCP (Transmission Control Protocol) is the "Quality Control" layer. I...]]></description><link>https://tcp-working-by-rahul.hashnode.dev/tcp-working-3-way-handshake-and-reliable-communication</link><guid isPermaLink="true">https://tcp-working-by-rahul.hashnode.dev/tcp-working-3-way-handshake-and-reliable-communication</guid><category><![CDATA[TCP]]></category><category><![CDATA[tcp working]]></category><category><![CDATA[ChaiCode]]></category><dc:creator><![CDATA[Rahul Ghosh]]></dc:creator><pubDate>Mon, 26 Jan 2026 14:13:13 GMT</pubDate><content:encoded><![CDATA[<h2 id="heading-what-is-tcp-and-why-is-it-needed">What is TCP and Why is it Needed?</h2>
<p>When you send data, routers along the way might get overwhelmed and drop your packets, or they might take different paths and arrive out of order.</p>
<p><strong>TCP (Transmission Control Protocol)</strong> is the "Quality Control" layer. It is needed because most applications (like your <strong>Express.js</strong> API or a banking app) cannot function if data is missing or scrambled. TCP turns an unreliable network into a reliable stream of data.</p>
<h2 id="heading-problems-tcp-is-designed-to-solve">Problems TCP is Designed to Solve</h2>
<p>Without TCP, developers would have to manually handle these three nightmares:</p>
<ol>
<li><p><strong>Packet Loss:</strong> Data disappearing into the "void" during transit.</p>
</li>
<li><p><strong>Out-of-Order Delivery:</strong> Packet #3 arriving before Packet #1.</p>
</li>
<li><p><strong>Data Corruption:</strong> Bits getting flipped (changing a <code>0</code> to a <code>1</code>) due to electrical interference.</p>
</li>
</ol>
<h2 id="heading-the-tcp-3-way-handshake">The TCP 3-Way Handshake</h2>
<p>Before any data (like an HTTP request) is sent, TCP must establish a "virtual circuit." It’s like a phone call where both parties confirm they can hear each other before starting the actual conversation.</p>
<h3 id="heading-the-steps-syn-syn-ack-ack"><strong>The Steps (SYN, SYN-ACK, ACK)</strong></h3>
<ol>
<li><p><strong>SYN (Synchronize):</strong> The Client sends a packet with a "Synchronize" flag and a random <strong>Sequence Number</strong> (e.g., <code>X</code>). It’s saying: <em>"I want to talk, and I'm starting my count at X."</em></p>
</li>
<li><p><strong>SYN-ACK (Synchronize-Acknowledge):</strong> The Server receives it and replies with its own random Sequence Number (<code>Y</code>) and an <strong>Acknowledgment Number</strong> (<code>X + 1</code>). It’s saying: <em>"I hear you! I'm starting my count at Y, and I'm ready for your packet X+1."</em></p>
</li>
<li><p><strong>ACK (Acknowledge):</strong> The Client replies with an Acknowledgment Number (<code>Y + 1</code>). It’s saying: <em>"Got it! We are connected. Sending data now."</em></p>
</li>
</ol>
<h2 id="heading-how-data-transfer-and-reliability-work">How Data Transfer and Reliability Work</h2>
<p>Once connected, TCP doesn't just "send and forget." It uses a <strong>Positive Acknowledgment with Re-transmission</strong> strategy.</p>
<ul>
<li><p><strong>Sequence Numbers:</strong> Every byte of data is numbered. This allows the receiver to put the packets back in the correct order if they arrive scrambled.</p>
</li>
<li><p><strong>Acknowledgments (ACKs):</strong> For every packet received, the receiver must send back an ACK. If the sender doesn't get an ACK within a certain timeframe, it assumes the packet was lost and <strong>re-sends it automatically</strong>.</p>
</li>
<li><p><strong>Checksums:</strong> Every packet has a mathematical "signature." If the data changes during flight, the signature won't match, and the receiver will discard the corrupted packet and ask for a fresh one.</p>
</li>
</ul>
<h2 id="heading-how-a-tcp-connection-is-closed">How a TCP Connection is Closed</h2>
<p>TCP is "Full Duplex," meaning both sides can send data at the same time. Because of this, closing a connection requires a <strong>4-way handshake</strong> so both sides can finish their "last words."</p>
<ol>
<li><p><strong>FIN (Finish):</strong> Client says, <em>"I'm done sending data."</em></p>
</li>
<li><p><strong>ACK:</strong> Server says, <em>"I hear you. I'm finishing up my last tasks."</em></p>
</li>
<li><p><strong>FIN:</strong> Server says, <em>"Okay, I'm done too."</em></p>
</li>
<li><p><strong>ACK:</strong> Client says, <em>"Confirmed. Goodbye."</em></p>
</li>
</ol>
]]></content:encoded></item></channel></rss>