#include "appserver.h" #include "clientthread.h" #include "../ytDMPServerDog/dogshm.h" AppServer::AppServer(QObject *parent) : QTcpServer(parent) { isWorking = false; UpTime = 0; logThread = new LogThread(this); AppPDataList.clear(); db = QSqlDatabase::addDatabase("QMYSQL"); db.setHostName("101.133.214.75"); db.setPort(3306); db.setUserName("usky"); db.setPassword("Yt#75Usky"); db.setDatabaseName("usky-cloud"); timer = new QTimer(this); connect(timer,&QTimer::timeout,this,&AppServer::timeout); timeout(); } void AppServer::start() { if(listen(QHostAddress::Any,51212)){ printf("listen 51212 start\n"); }else{ printf("listen failed\n"); exit(-1); } logThread->start(); timer->start(1000); } void AppServer::timeout() { if(!isWorking){ isWorking=true; uint t = QDateTime::currentDateTime().toTime_t(); dogshm->version_feedtime = t; if((t-UpTime)>1800){ if(db.open()){ QList tmpList; QStringList AppIDList; UpTime=t; QSqlQuery qry; AppIDList.clear(); qry = db.exec("select software_id from dmp_software_info"); while(qry.next()){ AppIDList.append(qry.value(0).toString()); } qry.clear(); for(int i=0;i0){ AppPDataList.clear(); AppPDataList.append(tmpList); } } } isWorking=false; } } void AppServer::commlog(QByteArray data, bool flag){ QString log = QString("[ %1 %2 ] ").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(flag?"<<<":">>>"); for(int i=0;iappendData(log); } void AppServer::datalog(QString log){ QString dat = QString("[ %1 ]").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")); dat.append(log); logThread->appendData(dat); } void AppServer::incomingConnection(qintptr socketDescriptor) { ClientThread *thread = new ClientThread(socketDescriptor,this); thread->setAppPDataList(AppPDataList); printf("AppPDataList0.length() [%d]\n",AppPDataList.length()); connect(thread,&ClientThread::commlog,this,&AppServer::commlog); connect(thread,&ClientThread::datalog,this,&AppServer::datalog); connect(thread,&ClientThread::finished,thread,&ClientThread::quit); thread->run(); }