首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >33. 传输层TCP协议十大主要特性(3) —— 连接管理(三次握手四次挥手)

33. 传输层TCP协议十大主要特性(3) —— 连接管理(三次握手四次挥手)

作者头像
小雨的分享社区
发布于 2022-10-26 07:51:52
发布于 2022-10-26 07:51:52
2210
举报
文章被收录于专栏:小雨的CSDN小雨的CSDN

连接管理

连接管理是分为两大块的: 1.建立连接:三次握手的过程 2.断开连接:四次挥手的过程

为什么要建立连接?

1.为了更好的保证可靠性,建立连接的过程就是让通信双方都确认验证一下各自的发送和接受能力是否能够正常 2.协商一些重要参数

建立连接:三次握手

假设我们现在在打电话,那么通信双方刚接通电话的时候就会有这样的情景:

TCP的实际连接过程中,是需要经历一下过程的:

三次握手中几个重要的状态: LISTEN:相当于手机打开了,有信号了,可以随时有人打电话进来 SYN_SEND/SYN_RCND:建立简介过程期间,如果建立连接顺利,这两个状态都是一瞬间就会消失的 ESTABLISHED:表示建立连接完成,可以开始正是通信了

断开连接:四次挥手

用两人分手的例子再来向大家做一些解释:

在TCP的实际连接过程中,是需要经历一下过程的:

对于CLOSE_WAIT的解释: 一般而言,对于服务器上出现大量的 CLOSE_WAIT 状态, 原因就是服务器没有正确的关闭 socket, 导致四次挥手没有正确完成. 这是一个 BUG. 只需要加上对应的 close 即可解决问题。(文件泄露问题)(一些文件出现相关异常也可能会导致跳过了close方法)

对于TIME_WAIT的解释: 谁主动断开连接,谁就进入了TIME_WAIT状态,到这一步的时候该主机已经完成了四次挥手的过程,但是仍然不能立刻释放资源,而是要以TIME_WAIT状态来保持一段时间的连接后在彻底释放资源(为了处理ACK丢包之后自动重传的问题,TIME_WAIT的时间是2MSL)

提问:

将三次握手改成两次行不行? 【不行,主机A还要给主机B应答,这样才能保证双方都能确认连接】 将三次握手改成四次行不行? 【行,但是没必要,因为ACK和SYN都在内核中,是同一时间发送的,把两个包合并成一个比较高效】 将四次握手改成三次行不行? 【ACK实在内核中的,FIN是需要处理完一些数据之后才会发送,ACK和FIN发送的时期不同,如果出发了延时应答机制(让ACK晚一会发送),就可以】

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021-03-27,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
Good Framework Rely on Good Api —— Six API Design Principles
发布于 2018-06-30 11:09 更新于 2018-08-12 08:04
walterlv
2018/09/18
5020
Good Framework Rely on Good Api —— Six API Design Principles
Awesome Java - 2017 Java 资源大合集
A curated list of awesome Java frameworks, libraries and software.
大数据工程师-公子
2019/03/14
2K0
The .NET of Tomorrow
Ed Charbeneau(http://developer.telerik.com/featured/the-net-of-tomorrow/) Exciting times lie ahead for .NET developers. During Build, Microsoft’s biggest developer event of the year, clear roadmaps were given on the future of .NET and C#. Microsoft is re-p
蒋金楠
2018/01/15
1.1K0
The .NET of Tomorrow
2020-5-10-RESTfulAPI中能否使用query string
之前2020-5-6-restful理解 - huangtengxiao和大家介绍了对RESTful的理解。然后就有小伙伴问了我灵魂问题,对于RESTfulAPI设计,是不是不能使用query string?
黄腾霄
2020/06/10
6290
What are APIs? Types of APIs
APIs have been revolutionizing the world since the birth of first-generation computers but they were not coded in high-level languages as they are being done today. The APIs are core concepts of programming which every programmer has to learn for achieving working levels of proficiency. As of now, APIs have reached a high level of sophistication which needs to be classified into types of APIs to get a good level of understanding.
用户4822892
2019/09/09
8880
What are APIs? Types of APIs
How to Add an API to your Web Service
Introduction APIs are a great way to extend your application, build a community, excite your users and get in on the Mashup Mania spreading across the web. While there’s plenty out there wanting in on the action, there’s a lot of questions about how to act
张善友
2018/01/29
8270
花椒服务端 gRPC 开发实践
在移动端平台开发中,为了增加代码复用,降低开发成本,通常会需要采用跨平台的开发技术,花椒也不例外。本次新的单品开发,由于时间紧,人员有限,经过调研选型,最终确定了 flutter 方案(具体选型过程不在本文讨论之内)。
CNCF
2019/12/05
3.6K1
花椒服务端 gRPC 开发实践
IBM i System Modernization - Need of Hour
IBM i has evolved overtime and organizations are modernizing their existing legacy systems to use the latest updates in IBM i. It is generally considered as old, obsolete and not trending just because it is in existence for 30 years. But replacing IBM i with some other technology is not worth it, instead IT teams must plan to modernize the existing IBM i systems of their organization. Now, modernizing is not as easy as it looks because the confusion here is which approach to choose among numerous options to update IBM i. The way you modernize your IBM I systems will decide the return you get after the updates. Some of the recommendations include unfolding the data and logic, improving the user interface and the software development process.
saurabhkumawat
2020/03/31
4500
IBM i System Modernization - Need of Hour
深入解析 RESTful API:从设计到实践的完整指南
在当今的互联网世界中,不同系统之间的数据交互和通信是构建现代应用的核心需求。无论是移动应用、Web 平台,还是微服务架构,RESTful API 都扮演着桥梁的角色。它以其简洁性、灵活性和可扩展性,成为开发者构建分布式系统的首选方案。本文将从基础概念到实际应用,一步步拆解 RESTful API 的设计与实现,助你掌握这一关键技术。
DevKevin
2025/02/16
7600
使用 swagger 生成规范化的RESTful API 代码
REST(英文:Representational State Transfer,又称具象状态传输)是Roy Thomas Fielding博士于2000年在他的博士论文[1] 中提出来的一种万维网软件架构风格,目的是便于不同软件/程序在网络(例如互联网)中互相传递信息。
goodspeed
2020/12/25
6.5K0
使用 swagger 生成规范化的RESTful API 代码
Go语言微服务框架 - 6.用Google风格的API接口打通MySQL操作
接下来,我们就尝试着实现通过RPC请求操作MySQL数据库,打通整个链路,真正地让这个平台实现可用。
junedayday
2021/10/14
1.2K0
为什么现在很多系统都采用api来进行数据交换
传统痛点: 早期系统常通过直接数据库访问或共享文件交换数据,导致系统高度耦合。例如:A 系统直接读写 B 系统的数据库表,一旦表结构变更,所有依赖系统崩溃。
用户11392210
2025/05/15
930
为什么现在很多系统都采用api来进行数据交换
API 工程化分享
本文是学习B站毛剑老师的《API 工程化分享》的学习笔记,分享了 gRPC 中的 Proto 管理方式,Proto 分仓源码方式,Proto 独立同步方式,Proto git submodules 方式,Proto 项目布局,Proto Errors,服务端和客户端的 Proto Errors,Proto 文档等等
郑子铭
2022/05/15
6360
API 工程化分享
Top 10 Python Frameworks for Web Development for 2020
Top Python Frameworks for Web Development for 2020. Top 10 Python Frameworks to Learn in 2020. Here are the top 10 Python frameworks for web development. Python is a programming language that needs any presentation. On the off chance that you are here, it most likely implies that you have some fundamental programming abilities and that you may be looking for roads to investigate increasingly over this specific language.
用户4822892
2019/11/06
6550
Top 10 Python Frameworks for Web Development for 2020
也许你并不需要 REST
Nearly 10 years ago, Leonard Richardson and Sam Ruby publishedRESTful Web Services. I remember eagerly waiting for that book before it came out. Today, REST is still regarded as the state-of-the-art API architecture. It's not hard to see its benefit in comparison to preceding RPC solutions of that time. RESTful APIs make sense, because of the obvious HTTP verb mapping to CRUD methods, and the ease at which individual resources may be addressed and cached in HTTP middleware.
李海彬
2018/07/26
4440
也许你并不需要 REST
架构师该如何为应用选择合适的API
架构师的主要活动是做出正确的技术决策。选择合适的API是一项重要的技术决策。那么今天就看看API的选择问题。
yuanyi928
2020/06/17
1.9K0
浅析 Open API 设计规范
背景 最近由于业务需求,我参与研发的云产品 CSB 需要对外开放 Open API,原本不是什么难事,因为阿里云内部的 Open API 开放机制已经非常成熟了,根本不需要我去设计,但这次的需求主要是针对一些独立部署的场景,需要自行设计一套规范,那就意味着,需要对 Open API 进行一些规范约束了,遂有此文。 Open API 和前端页面一样,一直都是产品的门面, Open API 不规范,会拉低产品的专业性。在云场景下,很多用户会选择自建门户,对接云产品的  Open API,这对我们提出的诉求便是构
kirito-moe
2022/06/22
3.1K0
Python资源列表-Awesome P
记得当初学C/C++,留下的深刻印象就是严肃、谨慎,特别关注功能函数实现,写代码前会经常看书,怕自己犯低级又不可知的错误,像那些经典《C和指针》、《C缺陷和陷阱》、《编程之美》等等,读到最后感觉这些书已经不是在写编程了,而是在写哲学,设计的美学,虽然现在都忘的一干二净了....
py3study
2020/01/08
1.5K0
Top 10 Web Development Trends in 2020
Web development is in a transformational period. Clients are at last starting to play out most of their internet perusing on cell phones and are rapidly moving from conventionally composed inquiries to voice searches. 
用户4822892
2020/01/17
1.2K0
RESTful 架构到底是什么?
REST这个词,是Roy Thomas Fielding在他2000年的博士论文中提出的。
JavaEdge
2021/10/18
6790
相关推荐
Good Framework Rely on Good Api —— Six API Design Principles
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档