我正在使用Qt lib在C ++中创建一个多客户端服务器(IRC)。我想知道它是否是一种很好的服务器架构方法。
我想避免为每个连接创建线程,所以我认为我可以在某种容器中拥有所有客户端套接字并使用ThreadPool执行操作(如处理传入的数据包)。
我唯一关心的是连接到SLOT
的套接字是否保证并行客户端处理。
代码:
CServer::CServer(QObject *parent) : QTcpServer(parent)
{
server = new QTcpServer(this);
connect(server, SIGNAL(newConnection()), this, SLOT(newConnection()));
if(!server->listen(QHostAddress::Any, 6667))
qDebug() << "Oh noes";
}
void CServer::newConnection(){
add server->nextPendingConnection() to the container
}
答案 0 :(得分:0)