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


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

固定长度



分隔符

固定长度字段+内容


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

边栏推荐
- SD_DATA_RECEIVE_SHIFT_REGISTER
- 测试3个月,成功入职 “字节”,我的面试心得总结
- mui侧边导航锚点定位js特效
- 财富证券证券怎么开户?通过链接办理股票开户安全吗
- Dragging the custom style of Baidu map to the right makes the global map longitude 0 unable to be displayed normally
- Afghan interim government security forces launched military operations against a hideout of the extremist organization "Islamic state"
- Easy to understand [linear regression of machine learning]
- [trusted computing] Lesson 12: TPM authorization and conversation
- [deep learning] 3 minutes introduction
- Pytorch中自制数据集进行Dataset重写
猜你喜欢
什么是敏捷测试
讨论 | AR 应用落地前,要做好哪些准备?
自动化测试:Robot FrameWork框架大家都想知道的实用技巧
Ansible learning summary (9) -- ansible loop, condition judgment, trigger, processing failure and other task control use summary
[tpm2.0 principle and Application guide] Chapter 1-3
原生js验证码
AI defeated mankind and designed a better economic mechanism
Mobile pixel bird game JS play code
[answer] if the app is in the foreground, the activity will not be recycled?
Tips of the week 136: unordered containers
随机推荐
深入浅出【机器学习之线性回归】
讨论 | AR 应用落地前,要做好哪些准备?
同消费互联网的较为短暂的产业链不同,产业互联网的产业链是相当漫长的
如何在软件研发阶段落地安全实践
面试官:页面很卡的原因分析及解决方案?【测试面试题分享】
AI defeated mankind and designed a better economic mechanism
Threshold segmentation based on RGB image and threshold adjustment by sliding
Tips for this week 140: constants: safety idioms
AI 击败了人类,设计了更好的经济机制
利用七种方法对一个文件夹里面的所有图像进行图像增强实战
Tear the Nacos source code by hand (tear the client source code first)
Sanxian Guidong JS game source code
Yarn capacity scheduler (ultra detailed interpretation)
Click on the top of today's headline app to navigate in the middle
debian10编译安装mysql
手撕Nacos源码(先撕客户端源码)
2022年理财产品的一般收益率是多少?
4种常见的缓存模式,你都知道吗?
[network attack and defense principle and technology] Chapter 4: network scanning technology
Pro2:修改div块的颜色