2

I'm using a QUdpSocket on Windows XP to send some data. At each 10 seconds, I'm sending about 100 to 500 packets each about 50 bytes. I don't have any problem on host sending small amount of packet each times. Problems occurs on host sending 500 packet and more each 10 seconds.

When using writeDatagram(...) I got the error message "Unable to send data". Majority of the 500 packets are sent (checked with wireshark) but some are not sent at all (last ones).

I think the problem occur when the socket's write buffer is full. But I have no idea how to check this with Qt to just wait the buffer to be ready to write more data.

Without Qt, I could use select(...) method to check if the socket is ready and send 1 byte at a time. But how could I check that with QUdpSocket. There's no such method. Also, bytesToWrite() seems to always return zero.

I know I can just sleep and retry but I don't think this method is reliable. The method can failed for other reason. The OS has a good method for this, it's called select().

Thank you for your help.

efficks
  • 139
  • 13
  • 1
    writeDatagram returns a value I think you should check that and when it returns -1 (error) you should wait a little and then retry. – Marco Mar 14 '16 at 13:20
  • Also, you said it you get the error "Unable to send data", but I don't see that in the QAbstractSocket::SocketError enumeration. Have you printed the result of the error() function? If your udp socket object is called myUdp you can call: `myUdp.error()` or `myUdp.errorString()` to get the error code. – code_fodder Mar 15 '16 at 07:13
  • I still have the problem. The Marco's solution does not seems ideal because, we can't know if the problem is from a full buffer or not. Yes, I'm sure of the error message. With a real socket, I would do a select. Can I do in in QT? – efficks Jul 04 '16 at 14:00

0 Answers0