TCP basics ===================================== .. panels:: :container: container-fluid p-4 bg-light :column: col-lg-12 .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What is TCP?** TCP stands for Transmission Control Protocol. It's one of the core protocols of Internet Protocol(IP) suite. TCP ensures reliable, ordered, and error-checked delivery of data between applications running on devices connected to a network. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **Why is TCP useful?** Without TCP, data sent over the internet could arrive out of order, get lost, or be duplicated. So TCP solves this by * Breaking data into Packets. * Ensuring all packets arrive correctly and in order. * Retransmitting lost packets. * This makes it ideal for applications where accuracy and reliability are critical like web browsing, email. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **How it works?** * Connection setup (3-way handshake) – The client and server exchange messages to establish a connection. * Data transfer – Data is broken into packets, sent, acknowledged, and reassembled in the correct order. * Error checking – TCP checks for errors and requests retransmission if needed. * Connection termination – Once data transfer is complete, the connection is closed gracefully. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **Where is TCP used?** * Web browsing – HTTP and HTTPS use TCP to load websites reliably. * Email – Protocols like SMTP, IMAP, and POP3 rely on TCP. * File transfers – FTP and other file-sharing tools use TCP for accurate data delivery. * Remote access – SSH and Telnet use TCP to ensure secure and reliable sessions. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **Why OSI Layer: Transport Layer (Layer 4)?** * It manages end-to-end communication between devices. * It handles segmentation, flow control, error correction, and retransmission. * It provides a reliable communication channel for applications running at the Application Layer (Layer 7). .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What are the key features?** * Connection-oriented. * Reliable data transfer. * Error detection and recovery. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What is a three-way handshake in TCP?** A process used to establish a TCP connection: * SYN – Client sends a synchronize request. * SYN-ACK – Server acknowledges and synchronizes. * ACK – Client acknowledges server's response. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What is a TCP segment?** A TCP segment is the unit of data sent over a TCP connection. It consists of: * TCP header (including sequence number, acknowledgment number, flags, etc.). * Data payload. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **How is retransmission handled in TCP?** If an ACK is not received within the timeout interval, TCP retransmits the segment. Modern TCP uses: * Timeout-based retransmission. * Fast retransmit (based on duplicate ACKs). .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What are some applications that use TCP?** * HTTP/HTTPS (Web). * FTP (File Transfer). * SMTP (Email). * Telnet / SSH (Remote Access). .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What is the working flow of TCP?** * Connection Establishment (3-Way Handshake): * Client sends SYN → Says I want to start a connection. * Server replies with SYN-ACK → Says Okay, I got it. Let's sync. * Client sends ACK → Says Confirmed. Let's communicate. * Data Transfer: * Data is broken into segments with sequence numbers. * Each segment is sent from sender to receiver. * Receiver sends ACKs back to confirm receipt. * TCP uses a sliding window to send multiple packets before waiting. * If data is lost or corrupted, TCP retransmits it. * Flow control makes sure the sender doesn’t overload the receiver. * Congestion control adjusts speed based on network traffic. * Connection Termination (4-Way Handshake): * Sender sends FIN → Says I’m done sending data. * Receiver sends ACK → Says Okay, I got it. * Receiver sends FIN → Says I’m done too. * Sender sends ACK → Says Goodbye. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What is the difference between a port and an IP address?** * IP address identifies a host in the network. * Port number identifies a specific process/service on that host. Together (IP + Port) = Socket. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **Is TCP Windows specific?** * No, TCP is not Windows-specific. * TCP is a standard protocol used across multiple platforms, including Windows, Linux, macOS, and others. * It is implemented in virtually all modern operating systems and is fundamental to networking. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **Is TCP Linux specific?** * No, TCP is not Linux-specific. * TCP is supported by all major operating systems, including Linux, Windows, macOS, and others. * It is the core protocol for reliable communication in most networks across different platforms. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **Which Transport Protocol is used by TCP?** * TCP (Transmission Control Protocol) itself is a transport layer protocol. * It provides reliable, connection-oriented communication between devices over a network. * TCP ensures data delivery and integrity by establishing a connection before transmitting data. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **Which Port is used by TCP?** * TCP does not use a specific port by itself. * However, applications using TCP assign specific port numbers for communication (e.g., HTTP uses port 80, HTTPS uses port 443). * Port numbers are assigned to different services and applications to ensure correct routing of data. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **Is TCP using Client-server model?** * Yes, TCP follows the client-server model. * The client sends a request to a server over a TCP connection, and the server responds to that request. * TCP ensures reliable data transfer between the client and server by establishing a connection before data exchange. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow Topics in this section, * :ref:`Learnings in this section ` * :ref:`Terminology ` * :ref:`Version Info ` * :ref:`TCP Version&RFC Details ` * :ref:`TCP Basic Setup on Ubuntu using IPv4 ` * :ref:`TCP Basic Setup on Ubuntu using IPv6 ` * :ref:`TCP Protocol Packet Details ` * :ref:`TCP Usecases ` * :ref:`TCP Basic Features ` * :ref:`TCP Core Protocols ` * :ref:`Reference links ` .. _TCP_step1: .. tab-set:: .. tab-item:: Learnings in this section * In this section, you are going to learn .. _TCP_step2: .. tab-set:: .. tab-item:: Terminology * Terminology .. _TCP_step3: .. tab-set:: .. tab-item:: Version Info * Version Info .. _TCP_step5: .. tab-set:: .. tab-item:: TCP Version&RFC Details .. csv-table:: :file: ./TCP_RFCdetails.csv :widths: 10,10,10,30 :header-rows: 1 .. _TCP_step25: .. tab-set:: .. tab-item:: TCP Basic Setup on Ubuntu using IPv4 * setup .. _TCP_step26: .. tab-set:: .. tab-item:: TCP Basic Setup on Ubuntu using IPv6 * setup .. _TCP_step6: .. tab-set:: .. tab-item:: TCP Protocol Packet Details **TCP SYN Packet** .. csv-table:: :file: ./TCP_SYN_Packet.csv :widths: 10,20,30,10 :header-rows: 1 **TCP SYN-ACK Packet** .. csv-table:: :file: ./TCP_SYN_ACK_Packet.csv :widths: 10,20,30,10 :header-rows: 1 **TCP ACK Packet** .. csv-table:: :file: ./TCP_ACK_Packet.csv :widths: 10,20,30,10 :header-rows: 1 **TCP SUBSCRIBE Packet** **TCP PSH-ACK Packet** .. csv-table:: :file: ./TCP_PSH_ACK_Packet.csv :widths: 10,20,30,10 :header-rows: 1 **TCP FIN Packet** .. csv-table:: :file: ./TCP_FIN_Packet.csv :widths: 10,20,30,10 :header-rows: 1 **TCP FIN-ACK Packet** .. csv-table:: :file: ./TCP_FIN_ACK_Packet.csv :widths: 10,20,30,10 :header-rows: 1 **TCP RST Packet** .. csv-table:: :file: ./TCP_RST_PACKET.csv :widths: 10,20,30,10 :header-rows: 1 .. _TCP_step7: .. tab-set:: .. tab-item:: TCP Usecases .. csv-table:: :file: ./TCP_Use_Cases.csv :widths: 10,20,30 :header-rows: 1 .. _TCP_step8: .. tab-set:: .. tab-item:: TCP Basic Features .. csv-table:: :file: ./TCP_Features.csv :widths: 10,10,30 :header-rows: 1 .. _TCP_step20: .. tab-set:: .. tab-item:: TCP Core Protocols .. csv-table:: :file: ./TCP_Core_Protocols.csv :widths: 10,10,10 :header-rows: 1 .. _TCP_step24: .. tab-set:: .. tab-item:: Reference links * Reference links