Transmission Control Protocol (TCP) is a protocol of transmission geared toward reliability. It is defined in RFC793.
TCP offers reliability to a communication system that is inherently not reliable.
TCP must recover damaged, lost or un-ordered data.
This reliability makes TCP a great choice for many networked applications. However this reliability comes at a price: both in performance and complexity.
Data encapsulation and multiplexing is possible using…
TCP Segments
TCP Segments are the Protocol Data Unit (PDU) of TCP: Segment Header and Segment Payload. In the Segment Header, the Source Port and Destination Port permit multiplexing.
TCP Connections
TCP is a connection-oriented protocol. It won’t start sending application data until a connection has been established between application processes.
In order to establish a connection, TCP uses a Three-way Handshake:
Sender Receiver
Sender send SYN Segments |\ |
| \ |
| \SYN |
| \ |
| \ |
| \ |
| \| Receiver receives SYN Segment,
| /| Responds with SYN ACK Segment
| SYN / |
| ACK/ |
| / |
| / |
| / |
Receiver receives SYN ACK Segment, |/ |
Responds with ACK Segment |\ |
| \ |
| \ACK |
| \ |
| \ |
| \ |
| \| Receiver receives ACK Segment,
| | Connection is established!
| |
| |
In order:
-
Sender sends a SYN message (a TCP Segment with the
SYN
flag set to1
) -
Upon receiving the SYN message, Receiver sends back a SYN ACK message (a TCP Segment with the
SYN
andACK
flags set to1
) -
Upon receiving the SYN ACK, the sender then sends an ACK message (a TCP Segment with the
ACK
flag set to1
)
Sender can start sending application data right after sending the ACK message, but Receiver needs to receive the ACK before sending anything back. One reason is to be able to synchronise SYN
sequence numbers used during the connection.
See also Two Generals’ Problem and this YouTube video for more an easy explaination.