当前位置: 首页 > news >正文

TCP连接状态说明

参考了网上一些文章,最终发现wireshark的wiki写的比较好,以此为基准,说明TCP在连接和断开时的状态迁移过程。

全局的TCP连接和断开的状态变更如下图所示:

TCP 3-way handshake

We assume that both host (A) and server (B) side start from CLOSED status.

  1. The server process create a TCB [1] and use TCB prepares to accept the host's request. After TCB born the server change status to LISTEN.

  2. The host does the same thing, create a TCB and use this TCB to send request, set the "SYN=1" in the request header, and initates a arbitrary sequence number, seq=x. SYN paccket (which means SYN=1) can not take any data content, but it will consume a sequence number. After request sent, the host goes into SYN-SENT status.

  3. After receiving the host's request:

    1. i. If the server accept to this connection, it will send back a confirm response. In the response both SYN and ACK bits should be '1', and server side also initiates a SEQ number, seq=y. The server will send its sequence number within packet which is used to be acknowledged to the clinet's SYN packet. This packet can not take any data content either, but it consumes a sequence number. So in this packet seq=y, ack=x+1. And the server goes into SYN-RCVD status.

    2. ii. If the server rejects the connection, it just responses a RST packet to reset the connection.

  4. After the host received the server's response, it will send back also a confirm packet with ACK bit sets to '1' and seq=x+1, ack=y+1. [2]

After that, both side gose into ESTABLISHED status. This is what we called three-way handshake.

Example

Capture Example

3-way handshake.pcap

[1]. TCB---Transmission Control Block, something like PCB, it stores some significant info like, TCP connectio table, the pointer for the sending and receiving buffer, retransmission queue pointer, the current sequence number and acknowledge number and ext.

[2]. ACK packet could take data content, if not, this packet will not consume SYN number. So the sequence number of the confirm packet is seq=x+1. But in practice, at times, TCP 3-way handshake not only just initiates the connection, but also negotiate some very important parameters. MSS (maximum segment size) negotiation occurs in this steps.

TCP 4-times close

  1. Client send finish datagram to the server, indicated that client will close the transmission from client to server. This is called active close. (FIN=1, seq=u)

  2. Server acknowledged the FIN datagram. (ACK=1, seq=v, ack=u+1)

  3. Server contiues to transmit, if the server finishs the transmission it will close transmission from server to client. This is called passive close.(FIN=1, ACK=1, seq=w, ack=u+1)

  4. Client acknowledged the FIN datagram to the server.[1] (ACK=1, seq=u+1, ack=w+1)

[1]. After the ACK send, the client will not release the resource immediately, it will turn into TIME-WAIT status and wait 2-MSL (Maximum Segment Lifetime) time to release resource.

Example

Capture Example

4 times close.pcap

状态迁移图

相关文章:

  • 嵌入式软件的分层架构
  • Cookie、Session、Token
  • 关于此站点更改通知.top域名后期将统一更换为snowytime.cn访问,其余top访问进入过渡期
  • 使用 Kotlin 和 Jetpack Compose 开发 Wear OS 应用的完整指南
  • Elasticsearch 性能优化面试宝典
  • Redis设计与实现——分布式Redis
  • 【从设置到上传的全过程】本地多个hexo博客,怎么设置ssh才不会互相影响
  • RAID学习笔记
  • vue 模板二次开发准备
  • WebXR教学 09 项目7 使用python从0搭建一个简易个人博客
  • 【Linux网络】NAT和代理服务
  • Python训练打卡Day26
  • Unbuntu 命令
  • Visual Studio2022跨平台Avalonia开发搭建
  • JVM 双亲委派机制
  • windows编写和调试代码工具——IDE安装
  • MATLAB中进行深度学习网络训练的模型评估步骤
  • .NET Core 中 Swagger 配置详解:常用配置与实战技巧
  • 【gitee 初学者矿建仓库】
  • 使用Maven部署应用到TongWeb(东方通应用服务器)
  • 莫高义在第四届中国新闻发言人论坛开幕式上的致辞
  • 101岁陕西省军区原司令员冀廷璧逝世,曾参加百团大战
  • 中国首艘海洋级智能科考船“同济”号试航成功,可搭载水下遥控机器人
  • 一种声音·阿甘本|即将到来的中世纪;“新”与“旧”……
  • 大环线呼之欲出,“金三角”跑起来了
  • 九江宜春领导干部任前公示,3人拟提名为县(市、区)长候选人