Skip to content
uencoder

TCP

TCP (Transmission Control Protocol) is a connection-oriented, reliable, ordered transport-layer protocol, establishing connections with a three-way handshake and providing sliding-window flow control and ACK-based acknowledgment.

Purpose

It provides reliable data transfer that arrives complete and in order, fitting file transfers and the Web.

Mechanism

A three-way handshake sets up the connection (SYN, SYN-ACK, ACK); a four-way close tears it down. Data is sequence-numbered and acknowledged by the receiver. Flow control uses a sliding window; congestion control uses slow start and AIMD. Retransmission happens on timeout. The state machine has 11 states.

Use cases

  • HTTP/HTTPS web transport
  • SSH remote login
  • SMTP mail transfer
  • File transfer (FTP/SFTP)

Examples

  • Input
    SYN seq=100
    Output
    SYN-ACK seq=200 ack=101

    The three-way handshake

Common errors

TIME_WAIT buildup exhausts ports
Tune tcp_tw_reuse or use a connection pool

Related terms

Related tools

References