TCP协议来自RFC793 。 https://www.ietf.org/rfc/rfc793.txt网络
1。 为何三次握手?this
正确答案:TCP三次握手,其实是双方各握手一次,各作一次确认,其中一次握手和确认合并在一块儿。(就这样简单,彻底没有别的幺儿子)。计算机网络
来此上面连接的Page27页。three
1) A --> B SYN my sequence number is X 2) A <-- B ACK your sequence number is X 3) A <-- B SYN my sequence number is Y 4) A --> B ACK your sequence number is Y
答案解释:TCP有2个特性1. “全双工” 2.“通讯稳定”ip
特性1须要双向确认,特性2引入了SEQ(sequence numbers 序列号),用SEQ肯定报文的先后顺序。ci
--错误答案:引用谢希仁著《计算机网络》第四版中,讲 “三次握手” 的目的是 “为了防止已失效的链接请求报文段忽然又传送到了服务端,于是产生错误”。这句话来自文首连接的Page 32的“The principle reason for the three-way handshake is to prevent old duplicate connection initiations from causing confusion”。rem
这句针对的问题应该是“若是协议只发SYN,不须要ACK就完成创建链接步骤可行吗?“get
即:it
1) A --> B SYN my sequence number is X 2) A <-- B SYN my sequence number is Y
后面一句很重要 “To deal with this, a special control message, reset, has been devised.” io
连一块儿解释就是若是2次握手,会出现失效的重复连接问题。3次握手+reset能够避免”失效的重复连接问题“!
2。 为何四次挥手?
正确答案:双方各挥手一次,各作一次确认。几乎和握手如出一辙,只是中间的2,3由于存在时间差没法合并。
1) A --> B FIN my sequence number is X 2) A <-- B ACK your sequence number is X 3) A <-- B FIN my sequence number is Y 4) A --> B ACK your sequence number is Y
RFC793给出的讨论在page38
There are essentially three cases: 1) The user initiates by telling the TCP to CLOSE the connection 2) The remote TCP initiates by sending a FIN control signal 3) Both users CLOSE simultaneously
就是说,只有case3的状况下,第2,3两步骤不存在时间差,能够作到3次挥手。但这种特例显然不该该被推荐为通用标准。更合理的4次挥手标准诞生了。