为什么三次握手的时候ack=seq+1

估计很多人都知道三次握手和四次挥手的过程,但这其中有一个问题困扰了我一会(其实是TM很久)

按照定义,seq是要发送的第一个字节的序号,ack等于他收到的seq序列号加上字节流数据的长度,他代表期望收到的下一个字节的序号,同时他也代表这个序号前的字节我都已经收到了。

那么为什么三次握手过程中,比如第一次握手,A向B发了seq=x,B给A回的ack是=x+1呢?如果有数据的话,那理应等于x+LEN,

如果没有数据,那就应该保持不动就等于x才对。

答案是在三次握手过程中:

The server responds to the client with a sequence number of zero, as this is its first packet in this TCP session, and a relative acknowledgement number of 1. The acknowledgement number is set to 1 to indicate the receipt of the client's SYN flag in packet #1.

Notice that the acknowledgement number has been increased by 1 although no payload data has yet been sent by the client. This is because the presence of the SYN or FIN flag in a received packet triggers an increase of 1 in the sequence. (This does not interfere with the accounting of payload data, because packets with the SYN or FIN flag set do not carry a payload.)

服务器端回复的这个+1,是代表他收到了SYN标示。

也就是说由于SYN或者FIN的存在,即使没有数据传输,但服务器端仍然需要通过+1来回应一句“我收到了”。因此握手过程中seq=x的话,ack = x+1。其他几次握手挥手也是同样道理。

P.S:SYN和FIN这种标示只占1bit

附上参考的文章,感谢~

https://aryb1n.github.io/2018/05/03/%E7%BD%91%E7%BB%9C-%E5%AF%B9ACK%E4%B8%80%E7%82%B9%E7%96%91%E6%83%91/

https://zhuanlan.zhihu.com/p/53374516

  • 21
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 16
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 16
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值