CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 2011
    Posts
    51

    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

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: Help on asynchronous WinInet or WinHttp

    There are some considerations from MSDN: https://support.microsoft.com/en-us/kb/275046
    Victor Nijegorodov

  3. #3
    Join Date
    Apr 2011
    Posts
    51

    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!

  4. #4
    Join Date
    Apr 2011
    Posts
    51

    Re: Help on asynchronous WinInet or WinHttp

    Quote Originally Posted by VictorN View Post
    There are some considerations from MSDN: https://support.microsoft.com/en-us/kb/275046
    Actually dwContext can be used to differentiate requests. Let me try.

    Thank you very much!

  5. #5
    Join Date
    Apr 2011
    Posts
    51

    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.

  6. #6
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    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.

  7. #7
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    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.

  8. #8
    Join Date
    Apr 2011
    Posts
    51

    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
  •  





Click Here to Expand Forum to Full Width

Featured