...recieve from client the fortune phrase's index(an integer data es. 'i' for QStringList.at[i]) and the server to answer with the requested phrase at index 'i'.
Could you indicate, in your experience, a way to approach to that problem?
Do I need to re-implement the QTcpSocket class in thread method run()?
Qt Code:
  1. void FortuneThread::run()
  2. {
  3. QTcpSocket tcpSocket;
  4. //! [1] //! [2]
  5. if (!tcpSocket.setSocketDescriptor(socketDescriptor)) {
  6. emit error(tcpSocket.error());
  7. return;
  8. }
  9. //! [2] //! [3]
  10.  
  11. QByteArray block;
  12. QDataStream out(&block, QIODevice::WriteOnly);
  13. out.setVersion(QDataStream::Qt_4_0);
  14. out << (quint16)0;
  15. out << text;
  16. out.device()->seek(0);
  17. out << (quint16)(block.size() - sizeof(quint16));
  18. //! [3] //! [4]
  19.  
  20. tcpSocket.write(block);
  21. tcpSocket.disconnectFromHost();
  22. tcpSocket.waitForDisconnected();
  23. }
  24. //! [4]
To copy to clipboard, switch view to plain text mode 
What is the best solution to read data from socket and then write?

I really appreciate your help, thanks.