当前位置:网站首页>TCP的粘包拆包问题解决方案
TCP的粘包拆包问题解决方案
2022-07-26 20:31:00 【公众号:知识浅谈】
TCP的粘包拆包问题解决方案
为什么TCP有而UDP没有粘包
1️⃣因为udp的数据包有保护边界。
2️⃣tcp是以字节流的形式,也就是没有边界,所以应用层的数据在传输层的时候就可能会出现粘包和拆包问题。
出现这种问题的原因图解
1️⃣字节流可以理解为一个双向的通道里流淌的数据,这个数据其实就是我们常说的二进制数据,简单来说就是一大堆 01 串。这些 01 串之间没有任何边界。
2️⃣应用层传到 TCP 协议的数据,不是以消息报为单位向目的主机发送,而是以字节流的方式发送到下游,这些数据可能被切割和组装成各种数据包,接收端收到这些数据包后没有正确还原原来的消息,因此出现粘包现象。
粘包情况
拆包情况
拆包&粘包

解决方案
应用层措施
1️⃣封装固定包的大小。
2️⃣在包的结尾加上固定的字符,比如:FTP中的解决方法:末尾加上\r\n
3️⃣消息头+消息体。消息头中有消息体的长度。
4️⃣自定义。
- END -边栏推荐
- 【Oracle实训】-部署号称零停机迁移的OGG
- Web3.0 时代,基于P2PDB实现一款Dapp的技术理论
- [pytoch foundation] torch.stack() function analysis
- MySQL -count: the difference between count (1), count (*), and count (column name)
- Some unexpected bug records
- Mysql -count :count(1)、count(*)、count(列名)的区别
- conda报错:json.decoder.JSONDecodeError:
- flask 源码梗概
- PLSQL package
- Leetcode array class
猜你喜欢

2022开放原子全球开源峰会议程速递 | 7 月 27 日分论坛议程一览

QT基础第一天 (1)QT,GUI(图形用户接口)开发

Detailed illustration of B-tree and its implementation in C language

关于:获取当前客户端登录的域控

【虚拟机数据恢复】意外断电导致XenServer虚拟机不可用的数据恢复
![[MySQL series] - how much do you know about the index](/img/d7/5045a846580be106e2bf16d7b30581.png)
[MySQL series] - how much do you know about the index

记一次invalid bound statement xxxxxx 问题解决思路

【HCIE安全】双机热备-主备备份

2022-7-26 第七组 抽象和接口

flask 源码梗概
随机推荐
SprinBoot面试题
关于:获取当前客户端登录的域控
In the era of Web3.0, the technical theory of implementing a DAPP based on P2P DB
idea中debug时如何进入指定的用户方法体中?
ROS2节点通信实现零拷贝
如何在一个项目中使用多种不同的语言?
记一次invalid bound statement xxxxxx 问题解决思路
留存收益率计算公式
Leetcode linked list problem -- 24. Exchange the nodes in the linked list in pairs (learn the linked list with one question and one article)
2022-7-26 第七组 抽象和接口
串口通信失败
Explain the 190 secondary compiler (decoding table) module of SMR laminated hard disk of Western data in detail
【HCIE安全】双机热备-主备备份
Custom annotation (I)
PLSQL package
Is it reliable, reliable and safe to open an account with a low commission for funds in Galaxy Securities
Leetcode array class
Set the template of core configuration file in idea
LeetCode_ Backtracking_ Medium_ 40. Combined sum II
Basic use of livedatade