Multithreaded HTTP requests

  • Thread starter Thread starter Christopher Marshall
  • Start date Start date
C

Christopher Marshall

Hi Chaps,

I'm trying to make repeated requests to a web service asyncronously so
the server can deal with the requests while the client does another
task, then the client can pick up the responses.

However when I access any server other than localhost the app only
ever returns two responses (this doesn't matter if I point it at my
web service or a public page like "http://www.microsoft.com"; it,
seemingly, only returns two wherever it is in the world). On
localhost it returns as many requests as are needed. RequestState is
from http://msdn.microsoft.com/library/d...uide/html/cpconMakingAsynchronousRequests.asp

Does anyone know what could be causing this?

Thanks for your help - Christopher


private void button1_Click(object sender, System.EventArgs e)
{
for ( int iRequestNumber = 0;
iRequestNumber < numRequests.Value;
iRequestNumber ++ )
{
string sURL = textBox2.Text;
HttpWebRequest httpRequest =
(HttpWebRequest) WebRequest.Create( sURL );
RequestState oRS = new RequestState();
oRS.Request = httpRequest;
oRS.m_oHostForm = this;
IAsyncResult ar = httpRequest.BeginGetResponse(
new AsyncCallback( reqCallBack ), oRS );
}
}

private static void reqCallBack( IAsyncResult ar )
{
RequestState oRS = (RequestState) ar.AsyncState;
WebRequest oReq = oRS.Request;
oRS.m_oHostForm.setOutput( "received response " +
oRS.GetHashCode().ToString() );
}
 
The referred article says:
Note It is critical that all network streams are closed. If you do not
close each request and response stream, your application will run out of
connections to the server and be unable to process additional requests.

Have you closed the response stream (default there is only two connections)
?
 
Back
Top