当前位置:网站首页>UDP RTP packet frame loss
UDP RTP packet frame loss
2022-06-28 12:29:00 【Fart pig】
udp Packet loss :
1. Sending packets continuously is too fast ( Each packet of data usleep(40));
2. Sending packet is too long ( Data is cut into 1400byte send out );
3. Too long processing time at the receiver leads to packet loss : call recv Method the receiving end receives data after , It took some time to process the data , Call again after processing recv Method ,
Between these two calls , The bag sent may be lost . In this case, the receiving end can be modified , Store the received packet into a buffer , Then quickly return to continue recv.
4. The packet sent is large , Exceeding the recipient cache results in packet loss : The bag exceeds mtu size several times , Several big udp The packet may exceed the recipient's buffer , Cause packet loss .
In this case, you can set socket Receive buffer . I have encountered this problem before , I set the receive buffer to 64K It's settled. .
Socket Buffer size modification and system settings :( Every Socket stay Linux Are mapped to a file , And with two buffers in the kernel ( Read buffer 、 Write buffer ) Related to . Or say , Every Socket Has two kernel buffers . Sometimes , We need to change the maximum kernel limit of the buffer , Make it meet our actual needs )
cat /proc/sys/net/core/rmem_max 212992
rmem_max: One Socket The maximum value of the read buffer that can be set by the program , Unit byte ;
wmem_max: One Socket The maximum write buffer that can be set by the program , Unit byte ;
rmem_default: One Socket When is created , Default read buffer size , Unit byte ;
wmem_default: One Socket When is created , Default write buffer size , Unit byte ;
Application level modification of buffer size
We can dynamically modify in the program ( adopt setsockopt system call ) Hold valid Socket Read / write buffer size of .
Copy code
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
int main(int argc, char **argv)
{
if (argc != 2)
{
printf("Usage: %s $RCFBUFSIZE
", argv[0]);
goto error;
}
int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if (sockfd < 0)
{
printf("create socket error=%d(%s)!!!
", errno, strerror(errno));
goto error;
}
// Check the system default socket Receive buffer size
int defRcvBufSize = -1;
socklen_t optlen = sizeof(defRcvBufSize);
if (getsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &defRcvBufSize, &optlen) < 0)
{
printf("getsockopt error=%d(%s)!!!
", errno, strerror(errno));
goto error;
}
printf("OS default udp socket recv buff size is: %d
", defRcvBufSize);
// Set according to the execution parameters UDP SOCKET Receive buffer size
int rcvBufSize = atoi(argv[1]);
if (rcvBufSize <= 0)
{
printf("rcvBufSize(%d) <= 0, error!!!
", rcvBufSize);
goto error;
}
printf("you want to set udp socket recv buff size to %d
", rcvBufSize);
optlen = sizeof(rcvBufSize);
if (setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &rcvBufSize, optlen) < 0)
{
printf("setsockopt error=%d(%s)!!!
", errno, strerror(errno));
goto error;
}
printf("set udp socket(%d) recv buff size to %d OK!!!
", sockfd, rcvBufSize);
// View the current UDP SOCKET Receive buffer size
int curRcvBufSize = -1;
optlen = sizeof(curRcvBufSize);
if (getsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &curRcvBufSize, &optlen) < 0)
{
printf("getsockopt error=%d(%s)!!!
", errno, strerror(errno));
goto error;
}
printf("OS current udp socket(%d) recv buff size is: %d
", curRcvBufSize);
close(sockfd);
exit(0);
error:
if (sockfd >= 0)
close(sockfd);
exit(1);
}
边栏推荐
- 案例驱动 :从入门到掌握Shell编程详细指南
- 分页样式 flex设置成在尾部显示(即使页数加长 也不会因为在末尾而换行)
- Remoteviews layout and type restriction source code analysis
- ASP.NET CORE Study06
- 期货开户有门槛吗,如何网上安全的开通期货账户
- Sha256 encryption tool class
- 【附源码+代码注释】误差状态卡尔曼滤波(error-state Kalman Filter),扩展卡尔曼滤波,实现GPS+IMU融合,EKF ESKF GPS+IMU
- Pyqt5 visual development
- Url追加参数方法,考虑#、?、$的情况
- [vi/vim] basic usage and command summary
猜你喜欢
随机推荐
MATLAB的官方网站上其实有很多MATLAB的学习和使用资料(文档、视频都有不少)
什么是泛型,怎么使用泛型分析
JNI函数的2种书写方式
SHA256加密工具类
吐血推荐17个提升开发效率的“轮子”
Build your own website (18)
杰理之wif 干扰蓝牙【篇】
攻防世界新手入门hello_pwn
js 期约与异步函数 Promise
Unity导入资源后还手动修改资源的属性?这段代码可以给你节约很多时间:AssetPostprocessor
How to get a generic type
真正的学懂三极管入门篇(经典)「建议收藏」
Is tongdaxin stock software reliable? Is it safe to trade stocks on it?
ByteV搭建动态数字孪生网络安全平台----助力网络安全发展
Two writing methods of JNI function
【C语言】文件读写函数使用
[vi/vim] basic usage and command summary
Login interface accesses and clears the token
ASP.NET CORE Study01
张同学回应首场直播带货


![[unity Editor Extension practice] dynamically generate UI code using TXT template](/img/20/1042829c3880039c528c63d0aa472d.png)





