TCP 3-Way Handshake Diagram
Below is a (very) simplified diagram of the TCP 3-way handshake process. Have a look at the diagram on the right as you examine the list of events on the left.
EVENT | DIAGRAM |
Host A 发送a TCP SYNchronize packet to Host B Host B receives A's SYN Host B 发送a SYNchronize-ACKnowledgement Host A 接收 B's SYN-ACK Host A 发送 ACKnowledge Host B 接收 ACK. TCP socket connection is ESTABLISHED. | TCP Three Way Handshake (SYN,SYN-ACK,ACK) |
SYNchronize and ACKnowledge messages are indicated by a either the SYN bit, or the ACK bit inside the TCP header, 首部数据and the SYN-ACK message has both the SYN and the ACK bits turned on (set to 1) in the TCP header.
TCP knows whether the network TCP socket connection is opening, synchronizing, established by using the SYNchronize and ACKnowledge messages when establishing a network TCP socket connection.建立TCP连接
When the communication between two computers ends, another 3-way communication is performed to tear down the TCP socket connection. This setup and teardown of a TCP socket connection is part of what qualifies TCP a reliable protocol. TCP also acknowledges that data is successfully received and guarantees the data is reassenbled in the correct order.传输层负责可靠的传输,TCP是面向有连接的,之所以可靠是因为有确认标识和确认机制。
Note that UDP is connectionless. That means UDP doesn't establish connections as TCP does, so UDP does not perform this 3-way handshake and for this reason, it is referred to as an unreliable protocol. That doesn't mean UDP can't transfer data, it just doesn't negotiate how the conneciton will work, UDP just transmits and hopes for the best.UDP没有TCP的握手流程,因此是不可靠的连接。也因此高效。