I'm useing QTcpSocket class to communicate between my QT-UI and my PLC.
Recently I changed my protocols, so that I can send large coherent chunks of data. The goal is to send string-data via TCP-protocol.
On the PLC-Side I delay the sending of the response by about 30 msec. Thats the time the PLC needs to process the string. The response is send, and I know on the UI-side to send the next one.
The Problem now is, the 30ms seem to be to long. A QTcpSocket::disconnected signal is emitted before the QTcpSocket::ReadyRead
signal.
Is there a way to modify when QTcpSocket::disconnected
is emitted? To set the timeout to 40 msec for example.
I tried tcpSocket->waitForReadyRead(100)
which also results in the disconnected signal beeing emitted.
tcpSocket->setSocketOption(QAbstractSocket::KeepAliveOption, 1);
had no result either.
The only way I can think of right now would be, to send the response immediately and implement a custom wait function, until the next string is to be send.
void WaitMS(int DurationMS)
{
QTime tWait;
tWait.start();
while(true){
QCoreApplication::processEvents();
if(tWait.elapsed()> DurationMS)
break;
}
}
This is an option, but it's a crude method.
Any help is appreciated.