mwvse
11th April 2020, 21:48
Hi,
Using Qt 5.14.1.
If I write back to back on a QUdpSocket, the subsequent datagrams never make it out. For example:
#include <QCoreApplication>
#include <QUdpSocket>
#include <QTextStream>
#include <QThread>
int main(int argc, char *argv[])
{
QTextStream cout(stdout);
QUdpSocket myUdpSocket;
myUdpSocket.connectToHost("127.0.0.1", 50000);
cout << myUdpSocket.write("msg 1\n") << Qt::endl;
cout << myUdpSocket.write("msg two\n") << Qt::endl;
QThread::currentThread()->sleep(5);
return 0;
}
Both writes return that they wrote the expected number of bytes (6 and 8).
Per Wireshark, only the first write (i.e., "msg 1\n") is actually sent out.
"1","0.000000","127.0.0.1","127.0.0.1","UDP","58","54399 ? 50000 Len=6","msg 1\n"
If I put in a delay, then it works:
cout << myUdpSocket.write("msg 1\n") << Qt::endl;
QThread::currentThread()->sleep(1);
cout << myUdpSocket.write("msg two\n") << Qt::endl;
Wireshark output:
"1","0.000000","127.0.0.1","127.0.0.1","UDP","58","53420 ? 50000 Len=6","msg 1\n"
"2","1.000014","127.0.0.1","127.0.0.1","UDP","68","53420 ? 50000 Len=8","msg two\n"
I also tried waitForBytesWritten(), and that didn't work (the calls to it each return false):
cout << myUdpSocket.write("msg 1\n") << Qt::endl;
cout << myUdpSocket.waitForBytesWritten(1000) << Qt::endl;
cout << myUdpSocket.write("msg two\n") << Qt::endl;
cout << myUdpSocket.waitForBytesWritten(1000) << Qt::endl;
I am fairly new to Qt so my apologies if I am missing something seemingly obvious. Any help understanding why QUdpSocket and/or write() is behaving this way is greatly appreciated. Thank you.
Using Qt 5.14.1.
If I write back to back on a QUdpSocket, the subsequent datagrams never make it out. For example:
#include <QCoreApplication>
#include <QUdpSocket>
#include <QTextStream>
#include <QThread>
int main(int argc, char *argv[])
{
QTextStream cout(stdout);
QUdpSocket myUdpSocket;
myUdpSocket.connectToHost("127.0.0.1", 50000);
cout << myUdpSocket.write("msg 1\n") << Qt::endl;
cout << myUdpSocket.write("msg two\n") << Qt::endl;
QThread::currentThread()->sleep(5);
return 0;
}
Both writes return that they wrote the expected number of bytes (6 and 8).
Per Wireshark, only the first write (i.e., "msg 1\n") is actually sent out.
"1","0.000000","127.0.0.1","127.0.0.1","UDP","58","54399 ? 50000 Len=6","msg 1\n"
If I put in a delay, then it works:
cout << myUdpSocket.write("msg 1\n") << Qt::endl;
QThread::currentThread()->sleep(1);
cout << myUdpSocket.write("msg two\n") << Qt::endl;
Wireshark output:
"1","0.000000","127.0.0.1","127.0.0.1","UDP","58","53420 ? 50000 Len=6","msg 1\n"
"2","1.000014","127.0.0.1","127.0.0.1","UDP","68","53420 ? 50000 Len=8","msg two\n"
I also tried waitForBytesWritten(), and that didn't work (the calls to it each return false):
cout << myUdpSocket.write("msg 1\n") << Qt::endl;
cout << myUdpSocket.waitForBytesWritten(1000) << Qt::endl;
cout << myUdpSocket.write("msg two\n") << Qt::endl;
cout << myUdpSocket.waitForBytesWritten(1000) << Qt::endl;
I am fairly new to Qt so my apologies if I am missing something seemingly obvious. Any help understanding why QUdpSocket and/or write() is behaving this way is greatly appreciated. Thank you.