当前位置:网站首页>Detailed explanation of TCP (3)
Detailed explanation of TCP (3)
2022-07-31 03:02:00 【Javanese Chicken @】
Article table of contents
9. Byte stream oriented
In this case of byte stream oriented, there is an important problem to pay attention to: the sticky packet problem (referring to the application side datagram)
For TCP, the data is transmitted as shown below
But for UDP, since UDP transmits datagrams, it is transmitted one by one
Then the question is, how to solve the sticky package problem?
Solve by designing a reasonable application layer protocol!!!
1. Set "terminator"/"delimiter" for application layer data
2. Set "length" for application layer data
Method 1:
Method 2:
10.Some exceptions in TCP
Common exceptions:
(1) Process termination
No matter how the process is terminated, the corresponding PCB will be released in essence, and the corresponding file descriptor will also be released, which will also trigger the wave four times.
"Process termination" does not mean that the connection is terminated. Process termination is actually equivalent to calling socket.close().
(2) Machine restart
When the machine restarts, it actually kills the process first, still waving four times.
(3) The machine is powered off/the network cable is disconnected
Unexpected!!The machine is too late to do anything
<1>It is the receiver who loses power
At this time, the other side is still sending data. Obviously, the sender will no longer have ACK at this time!
So the timeout is retransmitted. After several retransmissions, it will try to reset the connection and reset the segment.Then the sender will give up the connection, and the resources corresponding to the connection will be recycled.
<2>It is the sender who loses power
At this time, the other party is trying to receive data, but no data is received at this time
How does the receiver know that the sender is dead?Or is it that the sender hasn't sent it yet?
The strategy adopted by the receiver at this time is the "heartbeat packet" mechanism (also called "keep alive")
Every once in a while, send a PING packet to the other party and expect the other party to return a PONG packet.
If the PING packet has been sent, your bureau has no PONG after crossing the river, and you can't retry several times, it is considered that the other party has hung up.
Classic Interview Questions
How to achieve reliable transmission based on UDP protocol?
This question seems to be asking about UDP, but it is actually a TCP test!!!
1. Implement the confirmation response mechanism. After each data is received, Daou will feedback an ACK (this time this is not returned by the kernel, but the application defines an ACK packet and sends it back).
2. Realize serial number/confirm serial number, and realize deduplication.
3. Realize timeout retransmission.
4. Implement connection management.
5. To improve efficiency, implement a sliding window.
6. To limit the sliding window, implement flow control/congestion control.
7. Realize delayed response, piggyback response, heartbeat mechanism...
Which scenario is suitable to use TCP and which scenario is suitable to use UDP?
1. If reliability is required, TCP is preferred.
2. If the single data table of the number of beds is long (more than 64K), TCP is still used.
3. If you pay special attention to efficiency, give priority to UDP.
Typical scenario: communication between hosts in a computer room.
4. If broadcasting is required, UDP is preferred.
A piece of data is sent to multiple hosts at the same time. UDP itself supports broadcasting, but TCP itself does not support it. It can only send data to each host through multiple connections and polling in the application layer program.(pseudo broadcast).
边栏推荐
- YOLOV5学习笔记(三)——网络模块详解
- 字体压缩神器font-spider的使用
- 12 磁盘相关命令
- 开题报告之论文框架
- Go 项目实战-获取多级分类下的全部商品
- TCP详解(二)
- CentOS7下mysql5.7.37的安装【完美方案】
- 8. Unified exception handling (controller notifies @ControllerAdvice global configuration class, @ExceptionHandler handles exceptions uniformly)
- 选好冒烟测试用例,为进入QA的制品包把好第一道关
- 2022牛客多校联赛第四场 题解
猜你喜欢
Mycat's master-slave relationship, vertical sub-database, horizontal sub-table, and detailed configuration of mycat fragmented table query (mysql5.7 series)
10 Permission introduction
工程(五)——小目标检测tph-yolov5
Moxa NPort 设备缺陷可能使关键基础设施遭受破坏性攻击
接口测试关键技术
Basic learning about Redis related content
公司官网建站笔记(六):域名进行公安备案并将备案号显示在网页底部
知识蒸馏7:知识蒸馏代码详解
关于 mysql8.0数据库中主键位id,使用replace插入id为0时,实际id插入后自增导致数据重复插入 的解决方法
The application of AI in the whole process of medical imaging equipment
随机推荐
Refuse to work overtime, a productivity tool set developed by programmers
自动化办公案例:如何自动生成期数据?
刚出道“一战成名”,安全、舒适一个不落
选好冒烟测试用例,为进入QA的制品包把好第一道关
分布式与集群是什么 ? 区别是什么?
Huawei od dice js
Mycat's master-slave relationship, vertical sub-database, horizontal sub-table, and detailed configuration of mycat fragmented table query (mysql5.7 series)
YOLOV5 study notes (2) - environment installation + operation + training
CentOS7下mysql5.7.37的卸载【完美方案】
【shell基础】判断目录是否为空
YOLOV5 study notes (3) - detailed explanation of network module
Office automation case: how to automatically generate period data?
Pythagorean tuple od js
【Cocos Creator 3.5】缓动系统停止所有动画
Software accumulation -- Screenshot software ScreenToGif
LeetCode 每日一题 2022/7/25-2022/7/31
print task sorting js od huawei
2022牛客多校联赛第四场 题解
冒泡排序、选择排序、直接插入排序、二分法查找
LeetCode简单题之两个数组间的距离值