Hi,

I have a Server class which inherits from QTcpServer to accept the TCP connections. To handle each request in a custom way I have reimplemented QTcpServer::incomingConnection(). I have a custom class named 'ClientHandler' on server side which inherits from QTcpSocket and I am making the object of 'ClientHandler' class inside QTcpServer::incomingConnection(int socketDescriptor) and setting the socket descriptor to it.

Now I want to handle all the requests from the same TCP client by the same 'ClientHandler' object. To do that I am currently using the following code ...

Qt Code:
  1. void Server::incomingConnection ( int socketDescriptor )
  2. {
  3. if(socketDescClientHandlerMap.contains(socketDescriptor))
  4. {
  5. ClientHandler* clientHandler = socketDescHandlerClientMap.value(socketDescriptor);
  6.  
  7. //It seems we have to set socketDescriptor again to handle the next request
  8. clientHandler->setSocketDescriptor(socketDescriptor);
  9. }
  10. else
  11. {
  12. ClientHandler* clientHandler = new ClientHandler(this);
  13. socketDescClientHandlerMap[socketDescriptor] = clientHandler;
  14. clientHandler->setSocketDescriptor(socketDescriptor);
  15. }
  16. }
To copy to clipboard, switch view to plain text mode 

Is it the right way to do it? If not please suggest me the correct way...
(I checked peerPort() and peerAddress() - both of them seems useless for the current scenario)

Thanks in advance.