<?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://tcpworkingprinciple.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Wed, 02 Sep 2026 17:40:01 GMT</lastBuildDate><atom:link href="https://tcpworkingprinciple.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[TCP is a connection-oriented, reliable transport protocol that ensures data arrives:

Complete - No missing pieces

In order - Proper sequence

Uncorrupted - Exactly as sent

Without duplication - No repeats


Problems TCP Solves:

Packet Loss - Netw...]]></description><link>https://tcpworkingprinciple.hashnode.dev/tcp-working-3-way-handshake-and-reliable-communication</link><guid isPermaLink="true">https://tcpworkingprinciple.hashnode.dev/tcp-working-3-way-handshake-and-reliable-communication</guid><category><![CDATA[3-way handshake]]></category><dc:creator><![CDATA[Subhadip dutta]]></dc:creator><pubDate>Sun, 01 Feb 2026 07:49:26 GMT</pubDate><content:encoded><![CDATA[<p>TCP is a <strong>connection-oriented, reliable transport protocol</strong> that ensures data arrives:</p>
<ol>
<li><p><strong>Complete</strong> - No missing pieces</p>
</li>
<li><p><strong>In order</strong> - Proper sequence</p>
</li>
<li><p><strong>Uncorrupted</strong> - Exactly as sent</p>
</li>
<li><p><strong>Without duplication</strong> - No repeats</p>
</li>
</ol>
<h3 id="heading-problems-tcp-solves"><strong>Problems TCP Solves:</strong></h3>
<ol>
<li><p><strong>Packet Loss</strong> - Network congestion, router failures</p>
</li>
<li><p><strong>Out-of-Order Delivery</strong> - Packets taking different routes</p>
</li>
<li><p><strong>Data Corruption</strong> - Electrical interference, hardware errors</p>
</li>
<li><p><strong>Network Congestion</strong> - Too much traffic slowing everything down</p>
</li>
<li><p><strong>Connection Management</strong> - Knowing when to start and stop talking</p>
</li>
</ol>
<p><strong>Without TCP</strong>: Webpages would load with missing images, emails would arrive scrambled, file downloads would be unreliable.</p>
<p><strong>With TCP</strong>: You get perfect webpages, complete emails, and intact files—even over unreliable networks.</p>
<h2 id="heading-the-tcp-3-way-handshake-establishing-a-connection"><strong>The TCP 3-Way Handshake: Establishing a Connection</strong></h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769931651699/d9174420-6c98-45a2-aa2a-1261735c6a34.png" alt class="image--center mx-auto" /></p>
<p>Before any data transfers, TCP establishes a reliable connection using a <strong>3-way handshake</strong>. Think of it as a formal introduction:</p>
<h3 id="heading-step-1-syn-synchronize"><strong>Step 1: SYN (Synchronize)</strong></h3>
<p><strong>Client → Server</strong>: "I want to talk. My starting sequence number is 100."</p>
<ul>
<li><p>Client picks a random starting sequence number (e.g., 100)</p>
</li>
<li><p>Sets SYN flag = 1</p>
</li>
<li><p><strong>Meaning</strong>: "Can we establish a connection starting from sequence 100?"</p>
</li>
</ul>
<h3 id="heading-step-2-syn-ack-synchronize-acknowledgment"><strong>Step 2: SYN-ACK (Synchronize-Acknowledgment)</strong></h3>
<p><strong>Server → Client</strong>: "I acknowledge your 100. Let's start from my sequence 300."</p>
<ul>
<li><p>Server acknowledges client's SYN (Ack = 101, meaning "I expect sequence 101 next")</p>
</li>
<li><p>Server sends its own SYN with starting sequence number (e.g., 300)</p>
</li>
<li><p>Sets SYN flag = 1, ACK flag = 1</p>
</li>
<li><p><strong>Meaning</strong>: "Yes, let's connect. I start from 300, and I acknowledge your starting point."</p>
</li>
</ul>
<h3 id="heading-step-3-ack-acknowledgment"><strong>Step 3: ACK (Acknowledgment)</strong></h3>
<p><strong>Client → Server</strong>: "I acknowledge your 300. Let's begin!"</p>
<ul>
<li><p>Client acknowledges server's SYN (Ack = 301, meaning "I expect sequence 301 next")</p>
</li>
<li><p>Sets ACK flag = 1</p>
</li>
<li><p><strong>Meaning</strong>: "Connection established. We can now exchange data."</p>
</li>
</ul>
<blockquote>
<h2 id="heading-how-data-transfer-works-in-tcp"><strong>How Data Transfer Works in TCP</strong></h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769931857662/7ccada71-1e43-4475-9244-624169d1df79.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-how-tcp-ensures-reliability-order-and-correctness"><strong>How TCP Ensures Reliability, Order, and Correctness</strong></h2>
<h3 id="heading-reliability-handling-packet-loss"><strong>Reliability: Handling Packet Loss</strong></h3>
<p><strong>Problem</strong>: What if a packet gets lost?<br /><strong>Solution</strong>: <strong>Automatic Retransmission</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769932016448/17dd1f00-b29f-40a2-85cb-3e76f2cc70e3.png" alt class="image--center mx-auto" /></p>
<p><strong>How TCP knows when to retransmit:</strong></p>
<ol>
<li><strong>Timeout</strong>: If no ACK received within expected time</li>
</ol>
<p><strong>Duplicate ACKs</strong>: If receiver gets packets out of order (gets packet 3 before 2, it sends duplicate ACK for packet 1)</p>
<h3 id="heading-order-handling-out-of-order-delivery"><strong>Order: Handling Out-of-Order Delivery</strong></h3>
<p><strong>Problem</strong>: Packets may arrive in wrong order due to different network paths.<br /><strong>Solution</strong>: <strong>Sequence numbers + buffering</strong></p>
<h3 id="heading-correctness-handling-data-corruption"><strong>Correctness: Handling Data Corruption</strong></h3>
<p><strong>Problem</strong>: Bits might flip during transmission.<br /><strong>Solution</strong>: <strong>Checksums</strong></p>
<ul>
<li><p>Each packet includes a mathematical checksum</p>
</li>
<li><p>Receiver recalculates and compares</p>
</li>
<li><p>If mismatch → packet is corrupt → discarded (will be retransmitted)</p>
</li>
</ul>
<h3 id="heading-4-congestion-control-preventing-network-overload"><strong>4. Congestion Control: Preventing Network Overload</strong></h3>
<p>TCP slows down when it detects congestion:</p>
<ul>
<li><p><strong>Slow Start</strong>: Begin cautiously, increase speed gradually</p>
</li>
<li><p><strong>Congestion Avoidance</strong>: Grow window size slowly</p>
</li>
<li><p><strong>Fast Retransmit</strong>: On duplicate ACKs, retransmit immediately</p>
</li>
<li><p><strong>Fast Recovery</strong>: After recovery, don't start from scratch</p>
</li>
</ul>
<h2 id="heading-how-a-tcp-connection-is-closed"><strong>How a TCP Connection is Closed</strong></h2>
<p>TCP closes connections gracefully using a <strong>4-step termination</strong> (often called a 4-way handshake).</p>
<h3 id="heading-why-graceful-closure"><strong>Why Graceful Closure?</strong></h3>
<p>To ensure all data is delivered before closing. Imagine hanging up while someone is still talking!</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769932124353/0099f150-7ffe-47c5-8744-7a4edc44cfc0.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-step-by-step-termination"><strong>Step-by-Step Termination:</strong></h3>
<ol>
<li><p><strong>Client sends FIN</strong> (Finish): "I'm done sending data"</p>
</li>
<li><p><strong>Server sends ACK</strong>: "I acknowledge your FIN"</p>
<ul>
<li><p>At this point: Client → Server direction is closed</p>
</li>
<li><p>Server → Client direction may still be open</p>
</li>
</ul>
</li>
<li><p><strong>Server sends FIN</strong>: "I'm also done sending data"</p>
</li>
<li><p><strong>Client sends ACK</strong>: "I acknowledge your FIN"</p>
<ul>
<li>Connection fully closed after waiting period</li>
</ul>
</li>
</ol>
<p><strong>Why both sides send FIN?</strong> Because TCP is <strong>full-duplex</strong>—data can flow in both directions independently. Each side needs to close its sending direction.</p>
</blockquote>
]]></content:encoded></item></channel></rss>