想写一个简单的多线程服务器
于是就参考了qt example 里面的QThreadFortuneServer
这个例子在实现多线程服务器时,在监听函数里面开了一个线程 就是thread 对象。
void FortuneServer::incomingConnection(int socketDescriptor){ QString fortune = fortunes.at(qrand() % fortunes.size()); FortuneThread *thread = new FortuneThread(socketDescriptor, fortune, this); connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); thread->start();}
请问如果要是多个客户端同时连接是,是不是应该改成 thread数组?
FortuneThread *thread
每当有一个客户端连接的话就新建立一个对象?thread[i++]