C++ (Qt) QTimer::singleShot(0, &testClass, SLOT(startTest())); a.exec();
void TestClass::Tick(){ Connect(); QTimer::singleShot(1000, this, SLOT(Tick()));}
C++ (Qt)void TestClass::Connect(){ QTcpSocket *socket = new QTcpSocket(); socket->connectToHost(HostAddress, 80, QTcpSocket::ReadOnly); if (!socket->waitForConnected(1000) || socket->state() != QTcpSocket::ConnectedState || !socket->isValid()) { qDebug() << "Connection error";delete socket; return; } qDebug() << QString("Connected to %1").arg(HostAddress); socket->disconnectFromHost(); if (socket->state() != QAbstractSocket::UnconnectedState && !socket->waitForDisconnected(1000)) { socket->abort(); qDebug() << "Disonnection aborted";delete socket; return; } qDebug() << QString("Disconnected from %1").arg(HostAddress); delete socket;}