Help using QUdpSocket in blocking mode without an event loop
-
Hi
Having problems using qudpsocket in blocking mode
My code is below, runs in a seperate thread
@
void run()
{QUdpSocket s;
s.bind();forever
{//get data from other thread
//code to process data
//then send out on wire qint64 n; n = s.writeDatagram( buffer, len, QHostAddress("........."), port); s.flush(); s.waitForBytesWritten(-1); if (len != n) qDebug() << "Error sending data << qPrintable(s.errorString());
}
}@
The code was originally written using bsd sockets using sendto (socket.h) in blocking mode.
The writeDatagram function function sometimes fails with QAbstractSocket::NetworkError, however the original sendto never failed
I suppose the bottom line is how do I make the QUdpSocket writeDatagram function work like socket.h sendto function?
Thanks
-
you could try waitForBytesWritten
"Your text to link here...":http://doc.qt.nokia.com/4.8-snapshot/qabstractsocket.html#waitForBytesWritten