PDA

View Full Version : Single server checking multiple client simultaneously - How to?



canavaroski90
31st January 2014, 17:07
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.

anda_skoa
3rd February 2014, 10:49
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,
_

canavaroski90
5th February 2014, 15:56
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

anda_skoa
5th February 2014, 18:20
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 host:port pair, which I think is 6.

Cheers,
_

canavaroski90
6th February 2014, 11:54
Hi,

Now I have 2 new questions.

1. If I get same response from all clients and if I send 6 independent ip:port/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 ip:port 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

anda_skoa
6th February 2014, 12:46
1. If I get same response from all clients and if I send 6 independent ip:port/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.



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.


2. Could you please give more detail about ip:port 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.


Considering the all pairs, can i send 24 simutaneous and seperated request with just 1 QNetworkAccessManager?

Yes, I think you can.

Cheers,
_

canavaroski90
10th February 2014, 12:43
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.