# 11.TCP的三次握手过程？为什么会采用三次握手，若采用二次握手可以吗

答：建立连接的过程是利用客户服务器模式，假设主机A为客户端，主机B为服务器端。

（1）TCP的三次握手过程：主机A向B发送连接请求；主机B对收到的主机A的报文段进行确认；主机A再次对主机B的确认进行确认。

（2）采用三次握手是为了防止失效的连接请求报文段突然又传送到主机B，因而产生错误。失效的连接请求报文段是指：**主机\*\***&#x41;发出的连接请求没有收到主机**B的确认，于是经过一段时间后，主机**A又重新向主&#x673A;**\*\*B发送连接请求，且建立成功，顺序完成数据传输。**&#x8003;虑这样一种特殊情况，主机A第一次发送的连接请求并没有丢失，而是因为网络节点导致延迟达到主机B，**主机\*\***&#x42;以为是主机**A又发起的新连接，于是主机**B同意连接，并向主机**A发回确认，但是此时主机**A根本不会理会\*\*，主机B就一直在等待主机A发送数据，导致主机B的资源浪费。（这就是缺少第三次握手(A再给B确认））

（3）采用两次握手不行，原因就是上面说的实效的连接请求的特殊情况。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://im-qianuxn.gitbook.io/pytorch/ji-suan-ji/interview/11.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
