ich habe hier ein Problem mit einem einfachen TCP Client der auf QAbstractSocket aufsetzt:
Das Verhalten ist wiefolgt:
1. das Programm wird gestartet
2. es läuft einige Stunden und sendet alle 10 ms eine Botschaft an einen Client (in einer Endlosschleife)
3. dann kommt irgendwann der Zeitpunkt, an dem das Tool aufhört zu senden
4. die Verbindung bleibt erhalten (sowohl Client als auch Server zeigen mittels netstat an, das die Verbindung noch besteht! Aber es werden keine Daten mehr gesendet!
5. das Program kann mittels eine neue Verbindung aufbauen und weitersenden aber
Hatte jemand schonmal diese Problem?
Der Client läuft in einem WorkerThread und sendet in einer Endlosschleife:
Code: Alles auswählen
void workerThread::run()
{
openConnection();
init();
QList <telegram> liTelegrams = configService::getInstance()->getTeleList();
size.setNum ( liTelegrams.size() );
do
{
QList <telegram>::iterator it = liTelegrams.begin();
while ( it != liTelegrams.end() )
{
QList <QByteArray> lba;
QByteArray ba;
lba = ( it )->getMessageAsByteArray();
QList <QByteArray>::iterator itLBa;
itLBa = lba.begin();
while ( itLBa != lba.end() )
{
bool b;
int a = ( itLBa )->toInt ( &b, 16 );
ba.append ( ( char ) a );
itLBa++;
}
tcpSocket->write ( ba.data(), ba.size() );
tcpSocket->waitForBytesWritten ( -1 );
it++;
}
}
while ( configService::getInstance()->getRunAsLoop() );
}
void workerThread::init()
{
if ( tcpSocket == NULL )
{
tcpSocket = new QTcpSocket ( );
connect ( tcpSocket, SIGNAL ( error ( QAbstractSocket::SocketError ) ), this, SLOT ( slot_socketError ( QAbstractSocket::SocketError ) ) );
connect ( tcpSocket, SIGNAL ( readyRead() ), this, SLOT ( slot_newMsgReceived() ) );
connect ( tcpSocket, SIGNAL ( bytesWritten ( qint64 ) ), this, SLOT ( slot_bytesWritten ( qint64 ) ) );
}
}
void workerThread::openConnection()
{
init();
int state = tcpSocket->state();
if ( state != QAbstractSocket::ConnectedState )
{
QString tmpAddresse = configService::getInstance()->getServerAddress();
int tmpPort = configService::getInstance()->getServerPort();
tcpSocket->connectToHost ( tmpAddresse,tmpPort );
}
}
Hier der Aufruf des Sende Thread!
Code: Alles auswählen
void clientGui::slot_startPressed()
{
workerThread wThread;
wThread.openConnection();
wThread.start();
logService::getInstance()->addMsg ( "Starte Sende Thread!" );
}