当前位置:网站首页>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);
}
边栏推荐
- [unity Editor Extension practice] find all prefabs referencing this picture
- 深度学习又有新坑了!悉尼大学提出全新跨模态任务,用文本指导图像进行抠图...
- 【C语言】文件读写函数使用
- 关于字符串转换的一些小技巧
- 结构光之相移法+多频外差的数学原理推导
- [C language] use of nested secondary pointer of structure
- 2022年理财产品的常见模式有哪些?
- Unity Editor Extension Foundation, GUI
- Levels – virtual engine scene production "suggestions collection"
- JNI函数的2种书写方式
猜你喜欢
随机推荐
UGUI使用小技巧(五) Scroll Rect组件的使用
Unity WebGL移动端去除警告
请问通达信股票软件可靠吗?在上面交易股票安全吗?
websocket 1 分钟自动断开连接
Levels – virtual engine scene production "suggestions collection"
Vivo手机的权限管理
攻防世界新手入门hello_pwn
ASP.NET CORE Study08
fatal: unsafe repository (‘/home/anji/gopath/src/gateway‘ is owned by someone else)
内部振荡器、无源晶振、有源晶振有什么区别?
Android应用安全之JNI混淆
【C语言】如何很好的实现复数类型
Sha256 encryption tool class
杰理之wif 干扰蓝牙【篇】
Wechat authorized login
【Unity编辑器扩展基础】、EditorGUILayout (三)
group_concat学习与配置
Asynctask experience summary
微信授权登陆
pwn入门(1)二进制基础








