注:本文为 “TCP 序列” 相关文章合辑。
英文引文机翻未校。
TCP Sequence and Acknowledgement Numbers Explained
TCP 序列和确认编号说明
TCP Sequence (seq) and Acknowledgement (ack) numbers help enable ordered reliable data transfer for TCP streams. The seq number is sent by the TCP client, indicating how much data has been sent for the session (also known as the byte-order number). The ack number is sent by the TCP server, indicating that is has received cumulated data and is ready for the next segment.
TCP 序列 (seq) 和确认 (ack) 编号有助于为 TCP 流实现有序可靠的数据传输。seq 编号由 TCP 客户端发送,指示已为会话发送的数据量(也称为字节顺序号)。ack 编号由 TCP 服务器发送,表示已收到累积数据,并已准备好进行下一段。
The TCP seq and ack numbers are coordinated with one another and are key values during the TCP handshake, TCP close, and, of course, while data is transferred between the client and server.
TCP seq 和 ack 编号相互协调,是 TCP 握手、TCP 关闭期间的关键值,当然,在客户端和服务器之间传输数据时也是如此。
[By default, Wireshark converts all sequence and acknowledgement numbers into relative numbers. This means that all SEQ and ACK numbers always start at 0 for the first packet seen in each conversation.]
[默认情况下,Wireshark 将所有序列和确认编号转换为相对编号。这意味着对于每个会话中看到的第一个数据包,所有 SEQ 和 ACK 编号始终从 0 开始。
The picture below shows a real example of TCP sequence and acknowledgment numbers in a TCP flow diagram. The key variable is the TCP segment length for each TCP segment sent in the session.
下图显示了 TCP 流程图中 TCP 序列和确认编号的真实示例。key 变量是会话中发送的每个 TCP 分段的 TCP 分段长度。
The client sends the first segment with seq=1 and the length of the segment is 669 bytes. The server responds with an ack=670 which tells the client that the next expected segment will have a sequence number is 670.
客户端发送 seq=1 的第一个分段,该分段的长度为 669 字节。服务器以 ack=670 响应,这告诉客户端下一个预期的 segment 将具有 670 的序列号。
The next segment the client sends has seq=670 and the len is now 1460 bytes. In turn, the server responds with ack=2130 (670 + 1460). This cycle continues until the end of the TCP session.
客户端发送的下一个分段具有 seq=670,len 现在是 1460 字节。反过来,服务器以 ack=2130 (670 + 1460) 响应。此循环将持续到 TCP 会话结束。
Again, note that the length value is from the TCP segment length, not the Layer 2 frame length nor the IP packet length.
同样,请注意,length 值来自 TCP 分段长度,而不是第 2 层帧长度或 IP 数据包长度。
Seq and Ack in Wireshark
Wireshark 中的 Seq 和 Ack
Client sends seq=1 and tcp segment length=669
客户端发送 seq=1 且 tcp 段长度 = 669
Server responds with ack=670
服务器响应 ack=670
Client sends segment with seq=670 and length=1460
客户端发送 seq=670 且 length=1460 的 segment