saifulkhan
24th October 2013, 02:07
void FortuneThread::run()
{
QTcpSocket tcpSocket;
if (!tcpSocket.setSocketDescriptor(socketDescriptor)) {
emit error(tcpSocket.error());
return;
}
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_0);
out << (quint16)0;
out << text;
out.device()->seek(0);
out << (quint16)(block.size() - sizeof(quint16));
tcpSocket.write(block);
// Here !!
tcpSocket.disconnectFromHost();
tcpSocket.waitForDisconnected();
}
Say, in the fortune thread example, after sending (write) the text to the client, I want this particular thread to keep alive and keep reading different messages sent from the client, until client closes the connection (I guess by when client will invoke QTcpSocket ::abort() or QTcpSocket::disconnectfromHost()). Can you please suggest me how can I do this?
Thanks
{
QTcpSocket tcpSocket;
if (!tcpSocket.setSocketDescriptor(socketDescriptor)) {
emit error(tcpSocket.error());
return;
}
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_0);
out << (quint16)0;
out << text;
out.device()->seek(0);
out << (quint16)(block.size() - sizeof(quint16));
tcpSocket.write(block);
// Here !!
tcpSocket.disconnectFromHost();
tcpSocket.waitForDisconnected();
}
Say, in the fortune thread example, after sending (write) the text to the client, I want this particular thread to keep alive and keep reading different messages sent from the client, until client closes the connection (I guess by when client will invoke QTcpSocket ::abort() or QTcpSocket::disconnectfromHost()). Can you please suggest me how can I do this?
Thanks