What is TCP?
TCP is a reliable, connection-oriented protocol that ensures data is delivered correctly and in order over networks.
TCP (Transmission Control Protocol) is a reliable protocol for sending data over networks. It's like sending a registered letter with delivery confirmation — you know it arrived, and if it didn't, you'll be notified.
How TCP Works:
- Connection-oriented: Establishes a connection before sending data
- Reliable: Guarantees data arrives in order and intact
- Error checking: Detects and retransmits lost packets
- Flow control: Adjusts speed based on receiver's capacity
TCP vs UDP:
- TCP: Reliable, ordered, connection-based (like a phone call)
- UDP: Fast, unordered, connectionless (like shouting in a crowd)
TCP Handshake:
- SYN: Client says "I want to connect"
- SYN-ACK: Server says "OK, let's connect"
- ACK: Client says "Great, let's start"
- Data transfer begins
When TCP is Used:
- Web browsing: HTTP uses TCP
- Email: SMTP uses TCP
- File transfer: FTP uses TCP
- Anywhere reliability matters: When you need guaranteed delivery
FAQ
Is TCP always better than UDP?
No! TCP's reliability comes with overhead. For real-time games or video streaming, UDP's speed might be more important than perfect delivery.
What's the difference between TCP and HTTP?
TCP is the transport protocol (how data moves). HTTP is the application protocol (what the data means). HTTP runs on top of TCP.