QUdpSocket接收大量数据丢包
用QUdpSocket监听端口收数据,当数据量大时,如1秒500个udp包,结果存在大量丢包,不知道什么情况。
开始以为是处理不过来了,后来去掉了后续的处理过程,就仅接收下,可还是大量丢包,有人遇到过吗?
代码很简单,如下:
mMainUdp = new QUdpSocket;
connect(mMainUdp, SIGNAL(readyRead()), this, SLOT(readyReadMain()), Qt::DirectConnection);
mMainUdp->bind(g_mainPort, QUdpSocket::DefaultForPlatform);
void QCAdsDataReceive::readyReadMain()
{
while (mMainUdp->hasPendingDatagrams())
{
QByteArray datagram;
datagram.resize(mMainUdp->pendingDatagramSize());
QHostAddress sender;
quint16 senderPort;
mMainUdp->readDatagram(datagram.data(), datagram.size(),
&sender, &senderPort);
procAdsData(datagram);
}
}