^NyAw^
22nd May 2008, 17:42
Hi,
I have a class "CServer" that inherits from "QTcpServer". When it recives an incoming connection it creates a new QThread that recives the socketDescriptor.
void CServer::incomingConnection(int iSocketDescriptor)
{
CThread* pCThread = new CThread(this,iSocketDescriptor);
bool bC = connect(pCThread,SIGNAL(finished()),pCThread,SLOT( deleteLater()));
pCThread->start();
}
The Thread creates a Socket into "run()" method:
void CThread::run()
{
//Create the socket without parent
m_pqSocket = new QTcpSocketThread();
if (!m_pqSocket->setSocketDescriptor(m_iSocketDescriptor))
{
emit error(m_pqSocket->error());
return;
}
//Enter the eventLoop
exec();
//The client disconnects
m_pqSocket->waitForDisconnected();
delete (m_pqSocket);
}
The clients are sending data to the client, so the server has a thread that is reciving the data from the client.
One problem is that the, trying to connect 2 clients, the server creates 2 threads, but only the first thread that is responding tho the first client is responding. When the first client close the connection that makes the server thread to exit, then the second thread recives communication.
Also, the second thread don't recives all the data.
Am I doing something wrong on the code above?
Thanks,
I have a class "CServer" that inherits from "QTcpServer". When it recives an incoming connection it creates a new QThread that recives the socketDescriptor.
void CServer::incomingConnection(int iSocketDescriptor)
{
CThread* pCThread = new CThread(this,iSocketDescriptor);
bool bC = connect(pCThread,SIGNAL(finished()),pCThread,SLOT( deleteLater()));
pCThread->start();
}
The Thread creates a Socket into "run()" method:
void CThread::run()
{
//Create the socket without parent
m_pqSocket = new QTcpSocketThread();
if (!m_pqSocket->setSocketDescriptor(m_iSocketDescriptor))
{
emit error(m_pqSocket->error());
return;
}
//Enter the eventLoop
exec();
//The client disconnects
m_pqSocket->waitForDisconnected();
delete (m_pqSocket);
}
The clients are sending data to the client, so the server has a thread that is reciving the data from the client.
One problem is that the, trying to connect 2 clients, the server creates 2 threads, but only the first thread that is responding tho the first client is responding. When the first client close the connection that makes the server thread to exit, then the second thread recives communication.
Also, the second thread don't recives all the data.
Am I doing something wrong on the code above?
Thanks,