#include "infocenterserver.h" InfoCenterServer::InfoCenterServer(QObject *parent) : QTcpServer(parent) { clientList.clear(); } void InfoCenterServer::start() { if(!listen(QHostAddress::Any,6002)){ printf("listen 6002 failed\n"); this->appendData("listen 6002 failed"); exit(1); }else{ printf("listen on 6002\n"); this->appendData("listen on 6002"); } } void InfoCenterServer::incomingConnection(qintptr socketDescriptor) { printf("new incoming\n"); this->appendData("incomingConnection"); InfoClient *client = new InfoClient(socketDescriptor,this); clientList.append(client); connect(client,&InfoClient::write_error,this,&InfoCenterServer::write_error); connect(client,&InfoClient::sendlog,this,&InfoCenterServer::receivelog); connect(client,&InfoClient::finished,client,&InfoClient::quit); client->start(); } void InfoCenterServer::receivelog(QString recelog) { this->appendData(recelog); } void InfoCenterServer::appendData(QString emitlog) { emit weblog(emitlog); } void InfoCenterServer::write_error() { this->appendData("enter into InfoCenterServer::write_error()"); InfoClient *pClient = qobject_cast(sender()); QList::iterator i; for(i=clientList.begin();i!=clientList.end();i++){ InfoClient *client = *i; if(client==pClient){ clientList.removeAll(client); client->deleteLater(); } } }