Hi,

Using Qt 5.14.1.

If I write back to back on a QUdpSocket, the subsequent datagrams never make it out. For example:
Qt Code:
  1. #include <QCoreApplication>
  2. #include <QUdpSocket>
  3. #include <QTextStream>
  4. #include <QThread>
  5.  
  6. int main(int argc, char *argv[])
  7. {
  8. QTextStream cout(stdout);
  9. QUdpSocket myUdpSocket;
  10.  
  11. myUdpSocket.connectToHost("127.0.0.1", 50000);
  12.  
  13. cout << myUdpSocket.write("msg 1\n") << Qt::endl;
  14. cout << myUdpSocket.write("msg two\n") << Qt::endl;
  15.  
  16. QThread::currentThread()->sleep(5);
  17.  
  18. return 0;
  19. }
To copy to clipboard, switch view to plain text mode 
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:
Qt Code:
  1. cout << myUdpSocket.write("msg 1\n") << Qt::endl;
  2.  
  3. QThread::currentThread()->sleep(1);
  4.  
  5. cout << myUdpSocket.write("msg two\n") << Qt::endl;
To copy to clipboard, switch view to plain text mode 
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):
Qt Code:
  1. cout << myUdpSocket.write("msg 1\n") << Qt::endl;
  2.  
  3. cout << myUdpSocket.waitForBytesWritten(1000) << Qt::endl;
  4.  
  5. cout << myUdpSocket.write("msg two\n") << Qt::endl;
  6.  
  7. cout << myUdpSocket.waitForBytesWritten(1000) << Qt::endl;
To copy to clipboard, switch view to plain text mode 
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.