QUdpSocket writeDatagram fail. Error: "QAbstractSocket::NetworkError"
-
I need send big data in short time, but have a problem with QUdpSocket.
Simple test:#include <QUdpSocket> void Test_Fail_QUdpSocket(int packet_size) { qDebug() << "Start test, packet_size: " << QString::number(packet_size); QUdpSocket socket; socket.setSocketOption(QAbstractSocket::SendBufferSizeSocketOption, 10*1024*1024); // is not helped qint64 sended_all = 0; while(1) { QByteArray bytes(packet_size, 0xcc); //QUdpSocket socket; //if uncomment it - working, but too slow qint64 sended = socket.writeDatagram(bytes, QHostAddress("123.123.123.123"), 50000); if( sended<0 ) { qDebug() <<"Err: " << QString::number(socket.error()) << "\tSended: " << QString::number(sended_all); //I get error with any "sended_all": 7 - QAbstractSocket::NetworkError return; } socket.flush(); // is not helped sended_all += packet_size; } } int main(int argc, char *argv[]) { Test_Fail_QUdpSocket(256); }
If QHostAddress("127.0.0.1") - then all good with any packet_size <= 8192.
But if host addres is any real host in local network (1Gb) I get error with any packet_size (128,256,512,1024,2048,4096,8192)
and all targets(x86, x64).But if I use Windows sockets(Winsock2.h) and function "send_to()" then all good!
My: QT 5.5.1, MinGW_492_32, MSVC2013_32, MSVC2013_64.
-
you forgot to bind to the port,
socket.bind(50000);
-
@VRonin said in QUdpSocket writeDatagram fail. Error: "QAbstractSocket::NetworkError":
you forgot to bind to the port,
socket.bind(50000);
Binds UDP is needed if want to receive.
I think so problem in component, becase it is sends packets long without error if I choose a small package size (<512).
With windows sockets no such problem.