I have this program that does measurements over time by communicating with a device that is connected by cable directly to my computers network adapter. The communication is using UDP.
The problem here is that after N seconds the program fails to pick up a packet it is expecting (A request packet is sent to the device, and then it waits for the reply). I have a variable that decides how long to wait between each measurement, and by changing this I don't change N, so the number of packets sent is not relevant. If I restart the application and run a new sequence (as in a long string of measurements with delays in between), it simply stops after N seconds again.
Observed values for N: ~200s, ~320s. (It changes sometimes (possibly when rebooting))
I capture packets using wireshark, and according to that the packet is actually received by the network adapter, so it's not the device that is failing here. My application is using Qt and is written in C++.
I have my own UDP class that is using QUdpSocket which extends QAbstractSocket which in turn extends QIODevice, and I see that the readyRead signal is declared in the QIODevice class, this is the signal that I expect but fail to receive.
So what went wrong? Why is Qt not reacting? And why is it after a set amount of time? Please let me know if more specific details/code is needed.
Part of the constructor for my udp class
socket = new QUdpSocket();
socket->connectToHost(QHostAddress(*ipaddr), COM_LUX_PORT);
connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead()));
The readyRead slot in my udp class
void Udp::readyRead(){
// when data comes in
QByteArray buffer;
buffer.resize(socket->pendingDatagramSize());
QHostAddress sender;
quint16 senderPort;
socket->readDatagram(buffer.data(), buffer.size(),
&sender, &senderPort);
qDebug() << "1Message: " << buffer.toHex();
emit messageReceived(buffer);
}
Signals and slots in the header
signals:
/*!
Signal for transferring the received messages
*/
void messageReceived(QByteArray buffer);
public slots:
void readyRead();
void readyReadSock2();
void reConnectToIp(QString addr);
private slots:
void slotTimeout();
EDIT#1: I found this similar question, but there is a major difference, because I receive packets just fine until a certain point.
EDIT#2: Some relevant code.