My server handle many connections using multiple threads. i create the threads using the code
HandlerConnection *thread = new HandlerConnection( socketDescriptor, &user_list, this );
connect( thread, SIGNAL(finished()), thread, SLOT(deleteLater()) );
thread->start();
HandlerConnection *thread = new HandlerConnection( socketDescriptor, &user_list, this );
connect( thread, SIGNAL(finished()), thread, SLOT(deleteLater()) );
thread->start();
To copy to clipboard, switch view to plain text mode
on the constructor method of class HandleConnection there is the follow code
if(!clientSocket->setSocketDescriptor(socketDescriptor)){
emit error( clientSocket->error() );
return;
}
connect(clientSocket, SIGNAL(readyRead()), this, SLOT(receiveData()), Qt::DirectConnection );
forever{
}
exec();
clientSocket = new QTcpSocket();
if(!clientSocket->setSocketDescriptor(socketDescriptor)){
emit error( clientSocket->error() );
return;
}
connect(clientSocket, SIGNAL(readyRead()), this, SLOT(receiveData()), Qt::DirectConnection );
forever{
QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents);
}
exec();
To copy to clipboard, switch view to plain text mode
after that, the server receive and send data. however, that code in the first post does not work.
Thanks. Waiting for more replies.
Bookmarks