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


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

固定长度



分隔符

固定长度字段+内容


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

边栏推荐
- zdog.js火箭转向动画js特效
- [PaddleSeg源码阅读] PaddleSeg Validation 中添加 Boundary IoU的计算(1)——val.py文件细节提示
- yolo训练过程中批量导入requirments.txt中所需要的包
- Run Yolo v5-5.0 and report an error. If the sppf error cannot be found, solve it
- [trusted computing] Lesson 11: TPM password resource management (III) NV index and PCR
- AI 击败了人类,设计了更好的经济机制
- [trusted computing] Lesson 10: TPM password resource management (II)
- [principle and technology of network attack and Defense] Chapter 6: Trojan horse
- [principles and technologies of network attack and Defense] Chapter 3: network reconnaissance technology
- 手机app外卖订餐个人中心页面
猜你喜欢
目标检测1——YOLO数据标注以及xml转为txt文件脚本实战
Robot engineering lifelong learning and work plan-2022-
Machine vision (1) - Overview
Mobile pixel bird game JS play code
带动画的列表选中js特效
【蓝桥杯集训100题】scratch从小到大排序 蓝桥杯scratch比赛专项预测编程题 集训模拟练习题第17题
Year SQL audit platform
More than 10000 units were offline within ten days of listing, and the strength of Auchan Z6 products was highly praised
[distributed theory] (II) distributed storage
SD_DATA_RECEIVE_SHIFT_REGISTER
随机推荐
Tips for this week 140: constants: safety idioms
Live broadcast software construction, canvas Text Bold
Debian10 compile and install MySQL
Summary of debian10 system problems
回归测试的分类
debian10编译安装mysql
元宇宙带来的创意性改变
Backup Alibaba cloud instance OSS browser
Face recognition attendance system based on Baidu flying plasma platform (easydl)
[principles and technologies of network attack and Defense] Chapter 3: network reconnaissance technology
yolo训练过程中批量导入requirments.txt中所需要的包
js拉下帷幕js特效显示层
More than 10000 units were offline within ten days of listing, and the strength of Auchan Z6 products was highly praised
运行yolo v5-5.0版本报错找不到SPPF错误,进行解决
Robot engineering lifelong learning and work plan-2022-
手撕Nacos源码(先撕客户端源码)
2022年理财产品的一般收益率是多少?
Ansible 学习总结(9)—— Ansible 循环、条件判断、触发器、处理失败等任务控制使用总结
[trusted computing] Lesson 12: TPM authorization and conversation
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