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


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

固定长度



分隔符

固定长度字段+内容


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

边栏推荐
- 【4500字归纳总结】一名软件测试工程师需要掌握的技能大全
- Introduction to OTA technology of Internet of things
- [OKR target management] case analysis
- Import requirements in batches during Yolo training Txt
- 上市十天就下线过万台,欧尚Z6产品实力备受点赞
- < code random recording two brushes> linked list
- 原生js验证码
- Pro2: modify the color of div block
- 保证接口数据安全的10种方案
- swiper左右切换滑块插件
猜你喜欢
随机推荐
2021年全国平均工资出炉,你达标了吗?
Chapter 3 business function development (safe exit)
如何在软件研发阶段落地安全实践
基于RGB图像阈值分割并利用滑动调节阈值
List selection JS effect with animation
Hutool - 轻量级 DB 操作解决方案
物联网OTA技术介绍
cf:C. Factorials and Powers of Two【dp + 排序 + 选不选板子 + 选若干个数等于已知和的最少数】
Chapter 2 build CRM project development environment (database design)
数学分析_笔记_第11章:Fourier级数
Classification of regression tests
Sanxian Guidong JS game source code
Run Yolo v5-5.0 and report an error. If the sppf error cannot be found, solve it
[deep learning] 3 minutes introduction
自动化测试:Robot FrameWork框架大家都想知道的实用技巧
[answer] if the app is in the foreground, the activity will not be recycled?
[principles and technologies of network attack and Defense] Chapter 3: network reconnaissance technology
讨论 | AR 应用落地前,要做好哪些准备?
[trusted computing] Lesson 11: TPM password resource management (III) NV index and PCR
Simple loading animation









