What is TCP?
TCP stands for Transmission Control Protocol. It is one of the main protocols in the Internet protocol suite (TCP/IP) and provides reliable, ordered, connection-oriented communication between applications running on networked hosts.
Key points
- Purpose: TCP moves a stream of bytes between two endpoints reliably and in order, even when the underlying network may drop, duplicate, or reorder packets.
- Connection-oriented: Before data is exchanged, TCP establishes a session (a connection) using a three-way handshake (SYN, SYN-ACK, ACK). The connection is later closed with a teardown sequence.
- Reliability mechanisms:
- Sequence numbers: label bytes so the receiver can reorder segments and detect missing data.
- Acknowledgments (ACKs): the receiver confirms receipt of data; unacknowledged data is retransmitted.
- Checksums: detect corrupted segments.
- Retransmission timers: lost segments are resent when ACKs don’t arrive in time.
- Flow control: TCP uses a sliding window (receiver’s advertised window) so the sender does not overwhelm the receiver’s buffer.
- Congestion control: Algorithms (e.g., slow start, congestion avoidance, fast retransmit, fast recovery) adjust the sending rate in response to network congestion to avoid excessive packet loss.
- Segmentation: Large streams are broken into segments that fit the network’s Maximum Transmission Unit (MTU).
- Ports and multiplexing: TCP uses port numbers to deliver data to the correct application process (e.g., port 80 for HTTP, port 443 for HTTPS).
- Header: TCP segments include a header with source/destination ports, sequence and acknowledgment numbers, flags (SYN, ACK, FIN, RST, PSH, URG), window size, checksum, and options (e.g., MSS, timestamps).
When to use TCP vs UDP
- Use TCP when you need reliability, ordered delivery, and flow/congestion control (web browsing, file transfer, email).
- Use UDP when low latency, simple messaging, or multicast is more important than strict reliability (DNS queries, live audio/video, some gaming).
This is general educational information; for implementation details or protocol specification, consult RFC 793 and later updates/extending RFCs (for congestion control, options, etc.).