[Qt-interest] QUdp sockets stops receiving after a while
David Boosalis
david.boosalis at gmail.com
Thu Feb 25 15:13:58 CET 2010
Thank you for the reply, I'll try to create a stand along application that
reproduces the bug, but for now here is part of my code.
The UDP socket binds to the port 4005, in the thread's run methods. I bind
with the option QUdpSocket::ReuseAddressHint, but it does not matter if I
use it or not.
If you see anything below that looks bad, please let me know. Thank you
very much.
/***********************************************************************/
void NetworkThread::processPendingDatagramsSlot()
{
static int count =0; // see how long it runs for
uint j;
QString message;
quint32 qui;
qint32 modelID;
UserMessage::Type mt;
QList <QByteArray> *history;
QByteArray historyData;
QByteArray datagram;
qDebug() << "Process pending datagram, count = " << count++;
qint64 size = 0;
//while(dataSocket->hasPendingDatagrams()) {
// commented out this while loop as I thought it might be getting
// in some infinte loop.
datagram.resize(dataSocket->pendingDatagramSize());
size += dataSocket->readDatagram(datagram.data(),datagram.size());
qDebug() << "\tread in =" << size << "dg size = " << datagram.size();
// size & dg size are always the same
// }
QDataStream in(&datagram,QIODevice::ReadOnly);
QByteArray block;
in >> dataBlockSize;
in >> qui;
mt = (UserMessage::Type) qui;
if (mt == UserMessage::HistoricalData) {
qDebug() << "Have history...." << __FILE__;
in >> historyData;
if (historyData.size() < 1)
return;
qDebug() << "*************************************";
qDebug() << "Historical data , size = " << historyData.size();
QDataStream historyStream(&historyData, QIODevice::ReadOnly);
historyStream >> modelID;
history = new QList<QByteArray>();
historyStream >> *history;
qDebug() << "Num of history items = " << history->count();
if (history->count() < 1) {
blockSize = 0;
return;
}
emit setHistory(modelID,history);
}
else if (mt == UserMessage::ModelTickerUpdate) {
// qDebug() << "Have ticker update....";
processTickerData(in);
// in the same thread it parses the incoming data , creates a new
// Data class which sends a signal to the GUI thread that reads the
// data, and deletes the Data class
}
...
else {
qDebug() << "Unknown messge type in prcess pending datagram..." << mt;
}
}
}
On Thu, Feb 25, 2010 at 1:38 AM, Markus Goetz <Markus.Goetz at nokia.com>wrote:
> ext David Boosalis wrote:
>
>> I have a QUdpSocket that gets data just fine for quite some time, the data
>> is coming in fairly fast at every 100 miliseconds over the internet. But
>> then after receiving a lot of messages (Sometimes a lot is 4,000 messages,
>> sometimes it is over 8000 messages) it just stops receiving all messages.
>>
>> The server acts as the client and connects to the client for sending UPD
>> sockets. The server (I mean the client) still thinks it is connected and
>> sends data on its UdpSocket. It's QUdpSocket::state also reports that it is
>> connected. The problem is on Windows and Linux
>>
>> Does anyone have any insite as to why a QUdpSocket might stop after
>> working fine for some time. Should I periodically close the port used for
>> binding and reopen it.
>> .
>>
> No, but can you send a minimal example that reproduces the problem?
>
> I can't think of a reason this happens.
>
> Markus
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100225/9e6917ca/attachment.html
More information about the Qt-interest-old
mailing list