Results 1 to 6 of 6

Thread: Extend QTcpServer to handle multiple clients

  1. #1
    Join Date
    Apr 2009
    Posts
    63
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Default Extend QTcpServer to handle multiple clients

    I have a class that extends QTcpServer and listens on a specified port for an incoming client connection (i.e. using nextPendingConnection() and so on). Was wondering what the most elegant way would be to handle multiple clients connecting and keeping track of them. This implies being able to identify each one, so maybe I'd have to do something like overload "incomingConnection( int socketDescriptor )"?

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Extend QTcpServer to handle multiple clients

    For each QTcpSocket returned by QTcpServer::nextPendingConnection() you can store information such as remoteAddress, remotePort and so on.
    A camel can go 14 days without drink,
    I can't!!!

  3. #3
    Join Date
    Apr 2009
    Posts
    63
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Extend QTcpServer to handle multiple clients

    I assume you are referring to peerAddress() and peerPort()?

  4. #4
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Extend QTcpServer to handle multiple clients

    Yes. you're right. I'm sorry for the mistake
    A camel can go 14 days without drink,
    I can't!!!

  5. #5
    Join Date
    Apr 2009
    Posts
    63
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Extend QTcpServer to handle multiple clients

    So if multiple clients are connected and want to send data to the server, how should the server handle reading the data for each separate client (i.e. readyRead())?

  6. #6
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Extend QTcpServer to handle multiple clients

    there isn't a unique solution but you could use a QSignalMapper to map each readReady signal with a slot with a parameter that allow to distinguish the client who sent data.

    Read the documentation for use of QSignalMapper and try to use it.
    A camel can go 14 days without drink,
    I can't!!!

Similar Threads

  1. Replies: 4
    Last Post: 30th November 2010, 21:09
  2. QNetworkAccessManager can't handle multiple cookies?
    By krippy2k in forum Qt Programming
    Replies: 5
    Last Post: 7th June 2009, 23:12
  3. Replies: 4
    Last Post: 23rd May 2008, 09:42
  4. Replies: 1
    Last Post: 18th June 2006, 10:12
  5. 500 clients support
    By yxc154 in forum Qt Programming
    Replies: 3
    Last Post: 13th March 2006, 09:18

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.