您的位置 首页 golang

「粉丝追问」tcp协议篇-为什么握手三次,不能二次呢?

咱们首先看看RFC怎么说。

A three way handshake is necessary because sequence numbers are not tied to a global clock in the network, and TCPs may have different mechanisms for picking the ISN’s. The receiver of the first SYN has no way of knowing whether the segment was an old delayed one or not, unless it remembers the last sequence number used on the connection (which is not always possible), and so it must ask the sender to verify this SYN. The three way handshake and the advantages of a clock-driven scheme are discussed in [3].

第一个原因:传输可靠纬度

核心在于这一句: The receiver of the first SYN has no way of knowing whether the segment was an old delayed one or not.

我们来翻译一下: 如果是这种情况,TCP没办法知道当前发生过来的数据包是当前连接的,还是上一个连接的。

举个栗子:

连接信息:

客户端: 端口-8888

客户端ip: 1.1.1.1

Server端: 端口-80

目的ip: 2.2.2.2

异常场景:

首次建联:

1. 双端握手建联,使用同一个seq

2. 客户端给Server发送一个数据包,但是由于网络原因导致某个数据包并没有被送达

3. 客户端超时重传,Server端收到

4. 双端断开

二次建联(连接信息碰巧一致):

1. 双端握手建联,使用同一个seq

2. Server端突然收到了上一个连接没有被送达的包。

3. 凌乱了~

第二个原因:安全纬度

双端使用同一个seq,那么黑客简单的抓包就可以伪造数据,从而向外部发起攻击。

总结来说:

为了保证数据传输可靠性和安全性,则seq必须是双方自己生成的唯一编号,所以三次握手是必须的。

文章来源:智云一二三科技

文章标题:「粉丝追问」tcp协议篇-为什么握手三次,不能二次呢?

文章地址:https://www.zhihuclub.com/100612.shtml

关于作者: 智云科技

热门文章

网站地图