当前位置:网站首页>Game network UDP + FEC + KCP
Game network UDP + FEC + KCP
2022-08-04 15:07:00 【Ink Pond Ivory】
FEC mainly generates redundant data for the original transmission data, and then transmits them together. During the transmission process, if part of the original data is lost, the original data can be restored through the received part of the redundant information and part of the original data.This technology is widely used in streaming media to ensure a smooth video viewing experience when the network is delayed.Simply put, it is to exchange traffic for data integrity.
In games with high immediacy requirements, in order to improve the player's experience and immediacy, reliable UDP (such as KCP) is used instead of TCP for network transmission, mainly because the TCP transmission time overhead is relatively large.But it is only reliable UDP, and it is still stretched in the face of network delay. At this time, it is a good choice to add FEC technology to the protocol stack.
So how to access FEC?
Here it is recommended to learn charp-kcp, and realizedkcp+fec, where FEC is the RS-FEC algorithm.
FEC mainly generates M copies of redundant data through K copies of original data, and K+M data forms a FEC package. Any K copies of data in the FEC package can restore all original data.
FEC protocol in csharp-kcp:
Original data: | sequenceID | flag | bodyLen | source data |
Redundant data: | sequenceID | flag | redundant data |
sequenceID: the sequence number of each data
flag: distinguish between original data and redundant data
bodylen: the length of the original data
redundant data: redundant data, the length depends on the longest bodyLen in the K pieces of data
Sender:
Firstly receive K copies of upper layer (KCP) data for buffering and directly forward lower layer protocol (UDP), when the number of caches is equal to K, use FEC algorithm to generate M copies of original data, and send M copies of original data to the lower layer protocol separately,Then release K caches.
Receiver:
Through the flag, you can judge whether the data is original data or redundant data. The original data is cached and forwarded to the upper layer protocol (KCP), and the redundant data is also cached.
It is easy to know whether the original data and redundant data come from the same FEC packet through the sequenceID of the data.
After receiving each piece of data, check whether the original data in the FEC package where the data is located has been received, if not, whether K pieces of data in the FEC package have been received, if so, proceed directlyDecode, and forward the decoded original data to the upper-layer protocol.Then the cached data related to this FEC packet can be removed.
Note:
kcp bestMentioned in practice: In order to further increase the transmission speed, the lower layer protocol may use forward error correction techniques.It should be noted that forward error correction will solve the original packet based on redundant information.Do not input the same original data packet to KCP twice, otherwise, KCP will think that the other party has retransmitted, which will generate more acks and occupy extra bandwidth.
That is to say: it is possible that the FEC has just decoded the original data, and then received the decoded original data.If it continues to be forwarded to the upper layer, kcp receives the same data twice, which is mistaken for retransmission, resulting in more acks and extra bandwidth.It is best to record the received original data and eliminate duplicate data in time.
What to focus on while developing:
1 Reduce the repeated input of original data caused by decoding
2 The memory of the cached data is opened and released multiple times (for the client, it is a lot of GC)
3 Multi-layer protocol data encapsulation also has the problem of opening and releasing memory blocks multiple times (the practice in csharp-kcp is: when applying for space, leave enough protocol header space for the lower layer protocol)
4 The header part of the FEC protocol is mainly designed according to its own protocol stack.The upper-layer protocol in csharp-kcp is KCP. The KCP part will split the sent data. When it reaches the FEC layer, the amount of data is relatively small, so one transmission can be used as a piece of data in the FEC packet.If it is replaced with another protocol stack, and the amount of data sent each time is relatively large, it is best to do some fragmentation operations on the upper layer of the FEC.
Li Chao: WebRTC transmission and serviceQuality - Zhihu (zhihu.com)
Talk about network communicationThe basics of FEC_Jhuster's column of technical blog_51CTO blog
StreamingMedia Weak Network Optimization Road (FEC) - Introduction to FEC Principles
边栏推荐
- 如何和程序员谈恋爱
- 编译型与解释型编程语言的区别
- 第十六章 源代码文件 REST API 教程(一)
- [in-depth study of 4 g / 5 g / 6 g project - 50] : URLLC - 16 - the 3 GPP URLLC agreement, specification, technical principle of depth interpretation - 10 - high reliability technology - 1 - low codin
- 实际工作中的高级技术(训练加速、推理加速、深度学习自适应、对抗神经网络)
- Makefile syntax and usage notes
- Basic Introduction for PLSQL
- 从-99打造Sentinel高可用集群限流中间件
- Leetcode: 215 disorderly to find the first big k element in the array
- Database recovery
猜你喜欢

卖家寄卖流程梳理

Google plug-in. Download contents file is automatically deleted after solution

Flutter 运动鞋商铺小demo

Go 语言快速入门指南: 变量和常量

FTP协议抓包-工具wireshark与filezilla

郑轻新生校赛和中工选拔赛题解
![[Beiya data recovery] IBM System Storage storage lvm information lost data recovery solution](/img/1c/3c8c323e6ee3406d202e07f85bab21.jpg)
[Beiya data recovery] IBM System Storage storage lvm information lost data recovery solution

【北亚数据恢复】IBM System Storage存储lvm信息丢失,卷访问不了的数据恢复方案

JCMsuite Application: Oblique Plane Wave Propagation Transmission Through Aperture

【Web技术】1401- 图解 Canvas 入门
随机推荐
JCMsuite Application: Oblique Plane Wave Propagation Transmission Through Aperture
1403. Minimum Subsequence in Non-Increasing Order
leetcode:251. 展开二维向量
微软表示将向内部网络安全专家共享数据 为企业提供更安全保护
[in-depth study of 4 g / 5 g / 6 g project - 50] : URLLC - 16 - the 3 GPP URLLC agreement, specification, technical principle of depth interpretation - 10 - high reliability technology - 1 - low codin
【北亚数据恢复】IBM System Storage存储lvm信息丢失数据恢复方案
I love Tanabata hahaha
1403. 非递增顺序的最小子序列
MVCC实现过程
【云原生 | 从零开始学Kubernetes】kubernetes之StatefulSet详解
leetcode:241. 为运算表达式设计优先级
Sum of four squares, laser bombs
聊聊与苹果审核员的爱恨情仇
Redis 高可用
QT笔记——Q_INVOKABLE了解
本周讨论用户体验:Daedalus 的 Nemo 加入 Ambire,探索加密海洋
郑轻新生校赛和中工选拔赛题解
用了TCP协议,就一定不会丢包吗?
Bluetooth Technology|In the first half of the year, 1.3 million charging piles were added nationwide, and Bluetooth charging piles will become the mainstream of the market
leetcode: 259. Smaller sum of three numbers