-
July 28th, 2015, 02:36 PM
#1
Help on asynchronous WinInet or WinHttp
Hi, Folks,
I would like to create a http connection and send over multiple asynchronous requests and then handle the responses in a callback function.
How should I identify the request that each response corresponds to?
Thanks,
CR
-
July 28th, 2015, 03:18 PM
#2
Re: Help on asynchronous WinInet or WinHttp
Victor Nijegorodov
-
July 28th, 2015, 03:39 PM
#3
Re: Help on asynchronous WinInet or WinHttp
Thank you very much Victor. It is very helpful, but I could not find the answer to how to link requests and responses.
Say, I send out req 1 and req 2, and then receive a notification in the callback function. How to tell if the notification is for the req 1 or req 2?
Thanks!
-
July 28th, 2015, 03:50 PM
#4
Re: Help on asynchronous WinInet or WinHttp
Originally Posted by VictorN
Actually dwContext can be used to differentiate requests. Let me try.
Thank you very much!
-
July 28th, 2015, 04:37 PM
#5
Re: Help on asynchronous WinInet or WinHttp
Does any one know if the responses have to be in the same order as requests? Or in another word, is it possible to have multiple outstanding requests for the connection? This is the case for winhttp but not sure for WinInet API. Thanks.
-
July 29th, 2015, 06:42 AM
#6
Re: Help on asynchronous WinInet or WinHttp
responses can come out of order, and in fact even individual reads may arrive mixed (though in logical order per 'file').
so if you launch request 1, 2 & 3, it is perfectly possible that:
You receive file 3 entirely
you recieve half of file 2
you receive half of file 1
you recieve the other half of file 2
10 seconds nothing happens
you receive the other half of file 1
From a logical POV, since each request has it's own response handle, you won't notice anything of the simultaneous/mixed reception
however if you program your code to 'read all of a response at once' and not move onto reading the other files, you may not get the best possible performance out of this.
you can't control reception, it is the server sending the data that determines the order in which data packets arrive on your PC.
-
July 29th, 2015, 06:50 AM
#7
Re: Help on asynchronous WinInet or WinHttp
also, what the KB VictorN linked doesn't mention...
There can only be a limited amount of actually active pending actions on any one single server, servers hard-limit this to avoid connection flooding, and clients (such as wininet) typically obey the limit out of convenience. The limit is typically 4 or 6 outstanding connections. Any additional requests you make will end up being queued and handled when one of the other actions completes.
so while 'technically' you need to write your code such that if you lauch 100 simultaneous requests that request 100 'could' be received first, in practice, you'll actually have 1-6 actively pending with 7-100 being queued and handled in order they were added as previously actions complete.
-
July 29th, 2015, 08:22 AM
#8
Re: Help on asynchronous WinInet or WinHttp
OReubens, thank you so much for explaining this. I plan to create one session and connection for efficiency, create multiple asynchronous requests and then handle responses in a callback function. It seems to me WinHttp can have only one outstanding request at any time and all others will be held in a queue. As long as WinInet api supports more than one simultaneous requests, it should be possible to control the max number of simultaneous requests and handle receiving orders correctly. Thanks for confirming this.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|