为什么 tcp 连接终止需要 4 次握手? [英] Why tcp connect termination need 4-way-handshake?

查看:26
本文介绍了为什么 tcp 连接终止需要 4 次握手?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当连接建立时,有:

客户端------SYN----->服务器

Client ------SYN-----> Server

客户端<---ACK/SYN----服务器----①

Client <---ACK/SYN---- Server ----①

客户端------ACK----->服务器

Client ------ACK-----> Server

当终止到来时,有:

客户------FIN----->服务器

Client ------FIN-----> Server

客户端 <-----ACK------ 服务器 ----②

Client <-----ACK------ Server ----②

客户端 <-----FIN------ 服务器 ----③

Client <-----FIN------ Server ----③

客户端------ACK----->服务器

Client ------ACK-----> Server

我的问题是为什么②和③不能像①那样设置在同一个包中,即ACK和SYN设置在一个包中???

my question is why ② and ③ can not set in the same package like ① which is ACK and SYN set in one package ???

推荐答案

  • 三次握手(连接设置)中:服务器必须确认(ACK)客户端的SYN 并且服务器还必须发送自己的 SYN,其中包含服务器将在连接上发送的数据的初始序列号.
    这就是为什么服务器在单个段中发送其SYN和客户端SYNACK.
  • 在连接终止中:需要四段来终止连接,因为FINACK是每个方向都需要.
    (2) 表示接收到的 FIN(第一段)被 TCP 确认(ACK)
    (3) 意味着稍后收到文件结尾的应用程序将关闭其套接字.这会导致其 TCP 发送 FIN.
    然后最后一段将意味着系统上的 TCP 收到这个最终的 FIN 确认(ACK)FIN.
    • In the Three-Way Handshake (connection setup) : The server must acknowledge (ACK) the client's SYN and the server must also send its own SYN containing the initial sequence number for the data that the server will send on the connection.
      That why the server sends its SYN and the ACK of the client's SYN in a single segment.
    • In connection Termination : it takes four segments to terminate a connection since a FIN and an ACK are required in each direction.
      (2) means that The received FIN (first segment) is acknowledged (ACK) by TCP
      (3) means that sometime later the application that received the end-of-file will close its socket. This causes its TCP to send a FIN.
      And then the last segment will mean that The TCP on the system that receives this final FIN acknowledges (ACK) the FIN.
    • 这篇关于为什么 tcp 连接终止需要 4 次握手?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆