Computer Networks
CN Part-1
- What is a Computer Network?
- Goals and Applications of Computer Networking
- Computer Network Components
- Types of Computer Networks
- Network Topology
- Difference between Client Server and Peer to Peer Network
- Layered Architecture in Computer Networks
- Protocol Hierarchy in Computer Networks
- Interfaces and Services in Computer Networks
- Connection Oriented and Connectionless Services
- Service Primitives
- OSI Model
- TCP/IP Model
- Difference between OSI Model and TCP/IP Model
- Encapsulation and Decapsulation in Computer Networks
- Queueing Models in Computer Network
CN Part-2
- Physical Layer in Computer Networks
- Transmission Media in Computer Networks
- Analog and Digital Signals
- Data Rate and Bandwidth
- Encoding Techniques
- Multiplexing in Computer Networks
- Transmission Modes in Computer Networks
- Data Link Layer
- Framing in Data Link Layer
- Flow Control in Data Link Layer
- Error Control in Data Link Layer
- Error Detection and Correction in Computer Networks
- Stop and Wait Protocol
- Sliding Window Protocol
- SDLC(Synchronous Data Link Control) Protocol
- High-Level Data Link Control (HDLC) Protocol
- Point-to-Point Protocol (PPP)
CN Part-3
- MAC Sublayer and MAC Addressing
- Channel Allocation Methods
- ALOHA Protocol (Pure and Slotted ALOHA)
- CSMA/CD and CSMA/CA in Computer Networks
- Ethernet (IEEE 802.3)
- Wireless LANs (IEEE 802.11, Wi-Fi, and Bluetooth Basics)
- Network Layer and Design Issues
- IPv4 and IPv6 Protocols
- Addressing: IP Address, Subnetting, and Supernetting
- Routing Algorithms: Static vs Dynamic, Distance Vector, and Link State
- Routing Protocols: RIP, OSPF, and BGP
- Packet Switching and IP Fragmentation
- Network Layer Protocols: ICMP, ARP, RARP, DHCP, and NAT
CN Part-4
- Transport Layer and Functions
- Process-to-Process Delivery, Ports, and Sockets
- TCP Segment and Three-Way Handshake Connection Establishment
- UDP (User Datagram Protocol): Format and Features
- Flow Control and Error Control in Transport Layer
- Congestion Control: Leaky Bucket, Token Bucket, and TCP Congestion Control
CN Part-5
- Application Layer Architecture and Principles
- Domain Name System (DNS)
- Email Protocols: SMTP, POP3, and IMAP
- File and Web Protocols: FTP, HTTP, and HTTPS
- Remote Access Protocols: Telnet and SSH
- World Wide Web (WWW) and Web Architecture
- Network Security Basics: SSL, TLS, and Cryptography Fundamentals
TCP Segment Format and Connection Establishment (3-Way Handshake) in Computer Networks
TCP kya hai? (Transmission Control Protocol)
TCP (Transmission Control Protocol) Transport Layer ka sabse important protocol hai, jo unreliable IP network ke upar 100% Reliable, Connection-Oriented, aur Byte-Stream data delivery provide karta hai.
Jab aap koi file download karte hain ya web page open karte hain, toh ek single bit bhi corrupt ya missing nahi honi chahiye. Isliye web traffic (HTTP/HTTPS), file transfer (FTP), aur emails (SMTP) sabhi TCP par rely karte hain.
TCP communication shuru karne se pehle dono endpoints ke beech formal connection establish karta hai jise Three-Way Handshake kehte hain.
1. TCP Segment Format
TCP header ka minimum size 20 Bytes aur options ke saath maximum 60 Bytes hota hai:
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Source Port | Destination Port | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Sequence Number | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Acknowledgment Number | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Data | |U|A|P|R|S|F| | | Offset| Reserved |R|C|S|S|Y|I| Window Size | | | |G|K|H|T|N|N| | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Checksum | Urgent Pointer | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Options (0 to 40 Bytes) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Field | Size | Purpose aur Explanation |
|---|---|---|
| Source / Dest Port | 16 bits each | Sending aur Receiving applications ke Port numbers. |
| Sequence Number | 32 bits | Segment ke pehle data byte ka sequential number. Data reassembly aur in-order delivery ke liye use hota hai. |
| Acknowledgment Number | 32 bits | Next expected byte number (Cumulative ACK). Agar ACK = 501 hai, matlab receiver ne byte 500 tak sab kuch successfully receive kar liya hai aur ab byte 501 ka wait kar raha hai. |
| Data Offset (Header Length) | 4 bits | TCP header ka size 32-bit words mein. Minimum 5 (5 * 4 = 20 Bytes), Maximum 15 (60 Bytes). |
| Control Flags | 6 bits |
– URG: Urgent pointer field valid hai – ACK: Acknowledgment field valid hai – PSH: Push data immediately to application (no buffering) – RST: Reset connection immediately – SYN: Synchronize sequence numbers (Connection setup) – FIN: Terminate connection (No more data from sender) |
| Window Size | 16 bits | Flow control ke liye. Receiver batata hai ki uske buffer mein kitne bytes receive karne ki jagah baaki hai (Receiver Advertised Window – rwnd). |
| Checksum | 16 bits | TCP header, data, aur pseudo-IP header ki error checking ke liye mandatory checksum. |
2. TCP Connection Establishment: 3-Way Handshake
TCP connection establish karne ke liye Client aur Server ke beech 3 messages exchange hote hain:
Client (Host A) Server (Host B) | | | (LISTEN state) | (LISTEN state) | | |============== Step 1: SYN (Seq = x) ==============================>| (SYN_RCVD state) | Client: "Hi, let's connect! My initial seq number is x" | | | |<============= Step 2: SYN + ACK (Seq = y, Ack = x + 1) ============| | Server: "Got your SYN! My seq is y, and I expect x+1 from you" | | | | (ESTABLISHED state) | | | |============== Step 3: ACK (Ack = y + 1) ==========================>| (ESTABLISHED state) | Client: "Got your SYN! I expect y+1 from you. Connection open!" | | | <==================== Full-Duplex Data Transfer Begins ==============>
Step 1 (SYN): Client server ko ek segment bhejta hai jisme SYN = 1 flag set hota hai aur ek random initial sequence number Seq = x choose karta hai.
Step 2 (SYN-ACK): Server request accept karke reply karta hai: SYN = 1, ACK = 1, Ack = x + 1, aur apna initial sequence number Seq = y set karta hai.
Step 3 (ACK): Client server ke SYN ko acknowledge karta hai: ACK = 1, Ack = y + 1. Ab connection fully establish ho chuka hai aur dono sides data transmit kar sakti hain.
3. TCP Connection Termination (4-Way Handshake)
Kyunki TCP Full-Duplex hota hai, isliye connection band karne ke liye dono directions ko alag-alag close karna padta hai:
- Client bhejta hai:
FIN(Client: “Maine apna data bhej liya, ab main kuch nahi bhejunga”). - Server reply karta hai:
ACK(Server: “Got your FIN, client-to-server direction closed”). - Server apna remaining data khatam karke bhejta hai:
FIN(Server: “Mera data bhi khatam ho gaya”). - Client reply karta hai:
ACK(Client: “Got your FIN”). ClientTIME_WAITduration (2 * MSL) wait karta hai aur connection gracefully close ho jaata hai.
Summary Table
| TCP Phase | Summary |
|---|---|
| Header Size | 20 Bytes minimum to 60 Bytes maximum. |
| Connection Setup | 3-Way Handshake (SYN → SYN-ACK → ACK). |
| Connection Termination | 4-Way Handshake (FIN → ACK → FIN → ACK). |