-
Notifications
You must be signed in to change notification settings - Fork 11
/
accepter.cpp
34 lines (30 loc) · 958 Bytes
/
accepter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "accepter.h"
#include "tcpserver.h"
Accepter::Accepter(quint16 port_, int num_, QObject *parent)
:QThread(parent)
,port(port_)
,num(num_)
{
}
Accepter::~Accepter()
{
if(isRunning()){
quit();
wait();
}
qDebug() << "~Accepter";
}
void Accepter::run()
{
QScopedPointer<TcpServer> tcpServer(new TcpServer(num));
connect(tcpServer.data(), &TcpServer::destroyed, this, &Accepter::deleteLater);
connect(tcpServer.data(), &TcpServer::message, this, &Accepter::message);
connect(tcpServer.data(), &TcpServer::maxCount, this, &Accepter::maxCount);
connect(tcpServer.data(), &TcpServer::clientCount, this, &Accepter::clientCount);
if(!tcpServer->listen(QHostAddress::Any, port)){
qDebug() << "TcpServer online failure: " << tcpServer->errorString() << QThread::currentThreadId();
return;
}
qDebug() << "TcpServer online: " << QThread::currentThreadId();
exec();
}