当前位置:网站首页>你真的理解粘包与半包吗?3分钟搞懂它
你真的理解粘包与半包吗?3分钟搞懂它
2022-07-07 16:07:00 【InfoQ】
通俗的例子
实际情况


那如何解决粘包与半包问题呢?
- 粘包:这个思路其实很清晰,就是把它拆开呗,具体就是看怎么拆了,比如我们可以固定长度,我们规定每个包都是10个字节,那么就10个字节切一刀,这样拆开解析就 ok 了。
- 半包:半包其实就是信息还不完整,我们需要等接收到全部的信息之后再作处理,当我们识别这是一个不完整的包时候,我们先 hold 住,不作处理,等待数据完整再处理。这里关键点在于,我们如何才能知道此时完整了?上面说的固定长度其实也是一点,当然还有更多更好的解决方案,我们接着往下看。
- 固定长度
- 分隔符
- 固定长度字段+内容
【文章福利】另外小编还整理了一些C++后端开发面试题,教学视频,后端学习路线图免费分享,需要的可以自行添加:
学习交流群点击加入~
群文件共享
小编强力推荐C++后端开发免费学习地址:
C/C++Linux服务器开发高级架构师/C++后台开发架构师

固定长度



分隔符

固定长度字段+内容


总结
- FixedLengthFrameDecoder,固定长度
- DelimiterBasedFrameDecoder,分隔符
- LengthFieldBasedFrameDecoder,定长度字段+内容
最后
参考资料

边栏推荐
- 【深度学习】3分钟入门
- 五种网络IO模型
- [principle and technology of network attack and Defense] Chapter 7: password attack technology Chapter 8: network monitoring technology
- The report of the state of world food security and nutrition was released: the number of hungry people in the world increased to 828million in 2021
- [tpm2.0 principle and Application guide] Chapter 1-3
- mui侧边导航锚点定位js特效
- Using stored procedures, timers, triggers to solve data analysis problems
- 备份阿里云实例-oss-browser
- 保证接口数据安全的10种方案
- List selection JS effect with animation
猜你喜欢

JS pull down the curtain JS special effect display layer

带动画的列表选中js特效
![[trusted computing] Lesson 12: TPM authorization and conversation](/img/ce/619141fa0387ba42528f93b1781038.png)
[trusted computing] Lesson 12: TPM authorization and conversation

漫画 | 宇宙第一 IDE 到底是谁?

mui侧边导航锚点定位js特效

Using stored procedures, timers, triggers to solve data analysis problems

数学分析_笔记_第11章:Fourier级数

备份阿里云实例-oss-browser

Chapter 3 business function development (user access project)

4种常见的缓存模式,你都知道吗?
随机推荐
万字保姆级长文——Linkedin元数据管理平台Datahub离线安装指南
Mobile pixel bird game JS play code
开发一个小程序商城需要多少钱?
讨论| 坦白局,工业 AR 应用为什么难落地?
测试3个月,成功入职 “字节”,我的面试心得总结
Hutool - 轻量级 DB 操作解决方案
What is agile testing
In depth understanding of USB communication protocol
Youth experience and career development
[trusted computing] Lesson 10: TPM password resource management (II)
备份阿里云实例-oss-browser
2022年理财产品的一般收益率是多少?
上市十天就下线过万台,欧尚Z6产品实力备受点赞
How to clean when win11 C disk is full? Win11 method of cleaning C disk
财富证券证券怎么开户?通过链接办理股票开户安全吗
Native JS verification code
基于百度飞浆平台(EasyDL)设计的人脸识别考勤系统
List selection JS effect with animation
Slider plug-in for swiper left and right switching
Personal best practice demo sharing of enum + validation