Mandymo
13th October 2010, 22:25
If I am trying to connect to an invalid host, and, after the connection fails, I try to connect to a valid host, the connection still fails.
void testSoc::test()
{
switch (state)
{
case 0:
case 2:
case 4:
qDebug ("Connecting to a valid host. Should be Ok");
timeout->start(10000);
soc->connectToHost(VALID_HOST, VALID_PORT);
break;
case 1:
qDebug ("Connecting to a invalid port. Should fail");
timeout->start(10000);
soc->connectToHost(VALID_HOST, INVALID_PORT);
break;
case 3:
qDebug ("Connecting to a invalid host. Should fail");
timeout->start(10000);
soc->connectToHost(INVALID_HOST, VALID_PORT);
break;
}
}
void testSoc::checkConnection()
{
timeout->stop();
if (soc->state() == QAbstractSocket::ConnectedState)
{
connected();
} else {
qDebug ("Connection failed");
soc->disconnectFromHost();
if (soc->state() != QAbstractSocket::UnconnectedState)
soc->waitForDisconnected();
soc->close();
//delete soc;
//soc = new QSslSocket;
state ++;
test();
}
}
* and of course there is
connect (soc, SIGNAL(connected()),
this, SLOT(connected()));
connect (timeout, SIGNAL(timeout()),
this, SLOT(checkConnection()));
In this code, all gives the expected results, except for case 4 (including case 2, reconnecting after trying to connect to a valid host, with invalid port)
deleting and re-creating the socket does not help
(using Qt 4.4.3)
void testSoc::test()
{
switch (state)
{
case 0:
case 2:
case 4:
qDebug ("Connecting to a valid host. Should be Ok");
timeout->start(10000);
soc->connectToHost(VALID_HOST, VALID_PORT);
break;
case 1:
qDebug ("Connecting to a invalid port. Should fail");
timeout->start(10000);
soc->connectToHost(VALID_HOST, INVALID_PORT);
break;
case 3:
qDebug ("Connecting to a invalid host. Should fail");
timeout->start(10000);
soc->connectToHost(INVALID_HOST, VALID_PORT);
break;
}
}
void testSoc::checkConnection()
{
timeout->stop();
if (soc->state() == QAbstractSocket::ConnectedState)
{
connected();
} else {
qDebug ("Connection failed");
soc->disconnectFromHost();
if (soc->state() != QAbstractSocket::UnconnectedState)
soc->waitForDisconnected();
soc->close();
//delete soc;
//soc = new QSslSocket;
state ++;
test();
}
}
* and of course there is
connect (soc, SIGNAL(connected()),
this, SLOT(connected()));
connect (timeout, SIGNAL(timeout()),
this, SLOT(checkConnection()));
In this code, all gives the expected results, except for case 4 (including case 2, reconnecting after trying to connect to a valid host, with invalid port)
deleting and re-creating the socket does not help
(using Qt 4.4.3)