Results 1 to 7 of 7

Thread: Single server checking multiple client simultaneously - How to?

  1. #1
    Join Date
    Jan 2014
    Posts
    12
    Thanks
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Single server checking multiple client simultaneously - How to?

    Hi all,

    I'm trying to build a custom server which can check all the clients to check availability of them and gather some informations. All clients has their own webservers so I don't have to tackle with QTcpSocket. I'm just putting and get request via QNetworkAccessManager and waiting for the reply. When reply arrives, updating the GUI. And if someone select a client from gui I must serve latest informations about the selected client to the user.

    I'm trying to figure out how can it be done. I mean what type of struct should I use to accomplish that?

    Until now I've tried this way;
    - Read all client informations from database.
    - create a thread for each of clients.
    - send them required gui control pointers, so they can use these pointers to update their informations in runtime.

    But for example if I have 1500 clients then it means I have 1500 threads (WOW) and when all of them start to gather informations from clients at the same time 1500 get request will be done simultaneously. I wonder do I need 1500 threads? But after that I'm thinking that if I try to do this with a single thread all of the get requests will be done sequential and if I have 100 clients and do sequential request, if all of them reply with maximum timeout of QNetworkAccess::get method, then the user will wait (100 * maximumtimeout) secs to gather information all of them.

    How can it be accomplished via another way? I couldn't figure out.

    Thanks for help.

    Edit:
    In current status of the project, client object is subclassing QThread and reimplementing run() method. And another mainclass is creating one for each client and start it.
    Last edited by canavaroski90; 31st January 2014 at 18:13.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Single server checking multiple client simultaneously - How to?

    Quote Originally Posted by canavaroski90 View Post
    But after that I'm thinking that if I try to do this with a single thread all of the get requests will be done sequential and if I have 100 clients and do sequential request
    QNetworkAccessManager does not serialize requests, it can handle multiple of the in parallel.

    Each returned QNetworkReply object will signal the progress and end of the respective request, a fast reply will end before a slow one even if the fast one was initiated before the slow one.

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    canavaroski90 (10th February 2014)

  4. #3
    Join Date
    Jan 2014
    Posts
    12
    Thanks
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Single server checking multiple client simultaneously - How to?

    Could you please refer me some examples about sending multiple request using QNetworkAccessManager?
    And is there any limitations for maximum simultaneous request number? Ä°e. can I send 150 request at the same time?

    Thanks

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Single server checking multiple client simultaneously - How to?

    You just call the get() method (or any other operation method) as often as you need to.

    Each call returns its own QNetworkReply and therefore has its own status.
    You can connect to each of those or to the QNetworkAccessManager's finished() signal (which will then have the finished reply object as its argument):

    The only limit I am aware of is connections per hostort pair, which I think is 6.

    Cheers,
    _

  6. The following user says thank you to anda_skoa for this useful post:

    canavaroski90 (10th February 2014)

  7. #5
    Join Date
    Jan 2014
    Posts
    12
    Thanks
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Single server checking multiple client simultaneously - How to?

    Hi,

    Now I have 2 new questions.

    1. If I get same response from all clients and if I send 6 independent iport/path request, how can I know that which response belongs to which client? And if any of the clients not reply (i mean reply returns with error code), then how can i know which one of them has not replied?

    2. Could you please give more detail about iport pair? Assume that there is 1 QNetworkAccessManager, so does it mean I can send 6 request in total or 6 request per ip-port pair?
    ie.
    lets say there is 4 different ip-port pairs
    1.2.3.4:80
    1.2.3.4:81
    1.2.3.5:80
    1.2.3.6:80
    consider the first 2 pair: can i send 6 seperate and simultaneous request per pair? that means i can send 6 request per port hence ip address doesn't effect the limitation of requests. Considering the all pairs, can i send 24 simutaneous and seperated request with just 1 QNetworkAccessManager?

    thanks

  8. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Single server checking multiple client simultaneously - How to?

    Quote Originally Posted by canavaroski90 View Post
    1. If I get same response from all clients and if I send 6 independent iport/path request, how can I know that which response belongs to which client?
    Each request is handled by its own QNetworkReply instance. It contains the QNetworkRequest object that was used to initiate the operation, even has a convenience accessor for the URL.

    Quote Originally Posted by canavaroski90 View Post
    And if any of the clients not reply (i mean reply returns with error code), then how can i know which one of them has not replied?
    Those for which you have not gotten the finished() signal. If you want to impose some timeout, do that with a timer.

    Quote Originally Posted by canavaroski90 View Post
    2. Could you please give more detail about iport pair? Assume that there is 1 QNetworkAccessManager, so does it mean I can send 6 request in total or 6 request per ip-port pair?
    6 per pair, any number if you have different pairs.

    Quote Originally Posted by canavaroski90 View Post
    Considering the all pairs, can i send 24 simutaneous and seperated request with just 1 QNetworkAccessManager?
    Yes, I think you can.

    Cheers,
    _

  9. The following user says thank you to anda_skoa for this useful post:

    canavaroski90 (10th February 2014)

  10. #7
    Join Date
    Jan 2014
    Posts
    12
    Thanks
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Single server checking multiple client simultaneously - How to?

    Hi,

    Actually I see that I didn't ask 2 questions but 4 However thanks for replying all of them at once.

    These answers helped me a lot. Thank you very much.

Similar Threads

  1. Replies: 3
    Last Post: 11th December 2012, 21:48
  2. Replies: 1
    Last Post: 3rd January 2012, 22:15
  3. Painting in multiple QWidgets simultaneously
    By edepetete in forum Qt Programming
    Replies: 0
    Last Post: 17th October 2011, 18:21
  4. Replies: 7
    Last Post: 10th May 2010, 12:26
  5. tcp QT server - .Net c# client
    By soniaerm in forum Qt Programming
    Replies: 0
    Last Post: 21st April 2010, 23:15

Tags for this Thread

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.