K
K
Kalombyr2019-02-03 16:04:45
Qt
Kalombyr, 2019-02-03 16:04:45

What is the most correct way to read data from QUdpSocket?

Good day!
I took out the work with sockets in a separate thread and the question arose of how it would be most correct to receive packets.

Or, as usual, by subscribing to the event:

connect(_socket, &QUdpSocket::readyRead, this, &UDPStream::onReadyRead);

or in a thread loop
if (_socket->hasPendingDatagrams()) {
        QByteArray data;
        data.resize(_socket->pendingDatagramSize());
        .........
}


What happens if I poll with an interval of, for example, 3ms? I mean, will there be any losses until the next packet is processed? Those. Will all incoming UDP packets be placed in a queue and wait in it until they are read? If so, what is the size of this queue (I assume that the network card / system is already doing this, but still)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ighor July, 2019-12-27
@IGHOR

And it will work anyway. The size of the queue depends on the bandwidth and availability of the network adapter.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question