/* ShemaConnect = mysql://user:pass@host:port/databasename */
/*
ScanPort *portcheck = new ScanPort();
connect(portcheck, SIGNAL(result(int,int,bool)), this, SLOT(serveracess(int,int,bool)));
portcheck->SetUrl(QUrl(ShemaConnect));
portcheck->start(QThread::HighPriority);
*/
{
Q_OBJECT
public:
void SetUrl
( QUrl check_url ,
int maxtime
= 300 ,
QObject * redirect
= 0 ) {
url = check_url;
receiver = redirect;
Timeout = maxtime;
setTerminationEnabled(true);
}
protected:
void run()
{
m_Socket
->connectToHost
(url.
host(),url.
port(),
QIODevice::ReadOnly);
if (m_Socket->waitForConnected(Timeout)) {
if (m_Socket->waitForReadyRead(Timeout)) {
qDebug() << "### connect ok port " << url.port();
int loops = 0;
while (!t->atEnd()) {
loops++;
response = t->readLine();
qDebug() << loops << " line " << response;
}
emit result(url.port(),runtime(st),true);
quit();
} else {
m_Socket->close();
qDebug() << "### connect nooo on port " << url.port();
emit result(url.port(),runtime(st),false);
quit();
}
} else {
m_Socket->close();
qDebug() << "### connect nooo on port " << url.port();
emit result(url.port(),runtime(st),false);
quit();
}
}
{
return go.msecsTo ( now );
}
signals:
void result(int,int,bool); /* port , time , true = ok */
private:
int Timeout;
uint millisecond;
};
/* ShemaConnect = mysql://user:pass@host:port/databasename */
/*
ScanPort *portcheck = new ScanPort();
connect(portcheck, SIGNAL(result(int,int,bool)), this, SLOT(serveracess(int,int,bool)));
portcheck->SetUrl(QUrl(ShemaConnect));
portcheck->start(QThread::HighPriority);
*/
class ScanPort : public QThread
{
Q_OBJECT
public:
void SetUrl( QUrl check_url , int maxtime = 300 , QObject * redirect = 0 )
{
url = check_url;
receiver = redirect;
Timeout = maxtime;
setTerminationEnabled(true);
}
protected:
void run()
{
QTime st = QTime::currentTime();
m_Socket = new QTcpSocket();
m_Socket->connectToHost(url.host(),url.port(),QIODevice::ReadOnly);
if (m_Socket->waitForConnected(Timeout)) {
if (m_Socket->waitForReadyRead(Timeout)) {
qDebug() << "### connect ok port " << url.port();
QTextStream *t = new QTextStream( m_Socket );
t->setCodec(QTextCodec::codecForMib(106));
int loops = 0;
while (!t->atEnd()) {
loops++;
response = t->readLine();
qDebug() << loops << " line " << response;
}
emit result(url.port(),runtime(st),true);
quit();
} else {
m_Socket->close();
qDebug() << "### connect nooo on port " << url.port();
emit result(url.port(),runtime(st),false);
quit();
}
} else {
m_Socket->close();
qDebug() << "### connect nooo on port " << url.port();
emit result(url.port(),runtime(st),false);
quit();
}
}
int runtime( QTime go )
{
QTime now = QTime::currentTime();
return go.msecsTo ( now );
}
signals:
void result(int,int,bool); /* port , time , true = ok */
private:
QString response;
int Timeout;
QTcpSocket *m_Socket;
uint millisecond;
QUrl url;
QObject* receiver;
};
To copy to clipboard, switch view to plain text mode
Bookmarks