Results 1 to 3 of 3

Thread: Handling all requests from same tcp client in server side

  1. #1
    Join Date
    Mar 2010
    Posts
    11
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Handling all requests from same tcp client in server side

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Handling all requests from same tcp client in server side

    What exactly do you mean by "the same client"? Do you mean all requests from the same connection or all requests from any connection qualified by some id ("client id") or something else? Currently your code associates clients to socket numbers they are using which is very unlikely to be what you want as socket numbers are assigned randomly to connections.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2010
    Posts
    11
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Handling all requests from same tcp client in server side

    Thanks for your reply.

    I solved the problem. It was my mistake. I was making use of Qt's fortune client example for testing my server.It was making a new connection when ever a new request is send. Actually I wanted all requests from same connection to be handled by a particular client. Thanks once again.

Similar Threads

  1. Interception of GET requests to the server
    By artkor in forum Newbie
    Replies: 4
    Last Post: 29th September 2010, 08:59
  2. Retrieve Host Name at Server Side
    By hkaraoguz84 in forum Qt Programming
    Replies: 0
    Last Post: 24th August 2010, 15:02
  3. Webkit and Client Side Storage
    By bythos in forum Qt Programming
    Replies: 2
    Last Post: 23rd June 2010, 14:37
  4. server-side app CGI Programming.
    By jcr in forum Newbie
    Replies: 0
    Last Post: 15th January 2009, 10:37
  5. Client side password management
    By frikkasoft in forum Qt Programming
    Replies: 2
    Last Post: 12th December 2008, 10:23

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.