当前位置:网站首页>你真的理解粘包与半包吗?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
- 使用OneDNS完美解决办公网络优化问题
- 深度学习-制作自己的数据集
- [trusted computing] Lesson 11: TPM password resource management (III) NV index and PCR
- Understanding of 12 methods of enterprise management
- 原生js验证码
- Mui side navigation anchor positioning JS special effect
- Pro2: modify the color of div block
- 海量数据去重的hash,bitmap与布隆过滤器Bloom Filter
- [principle and technology of network attack and Defense] Chapter 1: Introduction
猜你喜欢

仿今日头条APP顶部点击可居中导航

三仙归洞js小游戏源码

万字保姆级长文——Linkedin元数据管理平台Datahub离线安装指南

Robot engineering lifelong learning and work plan-2022-

Machine vision (1) - Overview

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

Pytorch中自制数据集进行Dataset重写
![[4500 word summary] a complete set of skills that a software testing engineer needs to master](/img/82/acae52928b3ab48e9ecbf4ec436e5e.jpg)
[4500 word summary] a complete set of skills that a software testing engineer needs to master

Supplementary instructions to relevant rules of online competition
![[tpm2.0 principle and Application guide] Chapter 1-3](/img/28/7f6e848d5c12d175214d6cc5de7c8b.png)
[tpm2.0 principle and Application guide] Chapter 1-3
随机推荐
五种网络IO模型
Tips of the week 136: unordered containers
机器视觉(1)——概述
Machine vision (1) - Overview
手撕Nacos源码(先撕客户端源码)
Robot engineering lifelong learning and work plan-2022-
SD_DATA_RECEIVE_SHIFT_REGISTER
AI defeated mankind and designed a better economic mechanism
Mobile pixel bird game JS play code
[4500 word summary] a complete set of skills that a software testing engineer needs to master
仿今日头条APP顶部点击可居中导航
ICer知识点杂烩(后附大量题目,持续更新中)
机器人工程终身学习和工作计划-2022-
Mui side navigation anchor positioning JS special effect
[OKR target management] value analysis
USB通信协议深入理解
[OKR target management] case analysis
讨论 | AR 应用落地前,要做好哪些准备?
JS pull down the curtain JS special effect display layer
Explain it in simple terms. CNN convolutional neural network