Reputation: 53
Im sending not packed image (bmp) data from one application(unity) to another (QT) via udp splitting in frames (50Kb) and adding frameId to data. On other side I'm trying to integrate frames (using frameId) and after i collected all frames of one image I process it as image. If Im just catching frames and do not process them Im getting data in right sequence
void Server::readPendingDatagrams()
{
if (udpSocket->hasPendingDatagrams()) {
QByteArray datagram;
datagram.resize(udpSocket->pendingDatagramSize());
QHostAddress sender;
quint16 senderPort;
udpSocket->readDatagram(datagram.data(), datagram.size(),
&sender, &senderPort);
qDebug()<<datagram[0]; //frameId
//processTheDatagram(datagram);
}
}
I see "1 2 3 4 5 1 2 3 4 5 1 2 3 4 5" in console but if I uncomment processTheDatagram(datagram); I'm getting "1 3 4 1 2 4 2 4 5 2 3 5" it losses data while processing previous datagram. Where is the problem?? in udp buffer?
Upvotes: 3
Views: 3193
Reputation: 21
As a complement to @Jeremy Friesner 's second recommendation:
For QUdpSocket:
Upvotes: 2
Reputation: 73041
Where is the problem?? in udp buffer?
The problem is that if the socket's recv-buffer fills up, then any UDP packets the computer receives while the buffer is full will be dropped. That's not a bug, it's a 'feature' of how UDP works.
Dropped UDP packets are just a fact of life; any program that uses UDP has to deal with dropped UDP packets one way or another. Here are some ways you could deal with them (not all mutually exclusive):
Upvotes: 7