Limitations in HttpWebRequest ?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I am trying to get continous streams of data from the same web server using
this sample code. It works fine if i starts two threads from the same program
which continously stream different data from the same webserver, but as soon
as i start the third streama gainst the same webserver in a new thread i keep
getting timouts from the webrequest. If i start other streams (up to 25) from
other web servers i have no problems. So is there any known limitation in how
many streams i can do against the same webserver ? and any known workaround ?

Rgds, Henrik

---

wrs = (HttpWebRequest)WebRequest.Create(SomeURL);
wrs.Credentials = myCred;
wst = (HttpWebResponse)wrs.GetResponse();
str = wst.GetResponseStream();
 
Often people forget that the underlying connection created by the request is
not freed up
unless you call Close() on the response.
So, you hit the connection limit, and no more webrequests will go through.
Here is an example:

for(int i=0; i < 3; i++) {
HttpWebRequest r = WebRequest.Create("http://www.yahoo.com") as
HttpWebRequest;
HttpWebResponse w = r.GetResponse() as HttpWebResponse;
}

In the above, the third request will hang in GetResponse().

If you close the response, by calling Response.Close() ,
then the underlying connection gets freed up, and the request will succeed.
--Peter
 
Peter said:
Often people forget that the underlying connection created by the
request is not freed up
unless you call Close() on the response.
So, you hit the connection limit, and no more webrequests will go
through. Here is an example:

for(int i=0; i < 3; i++) {
HttpWebRequest r = WebRequest.Create("http://www.yahoo.com") as
HttpWebRequest;
HttpWebResponse w = r.GetResponse() as HttpWebResponse;
}

In the above, the third request will hang in GetResponse().

If you close the response, by calling Response.Close() ,
then the underlying connection gets freed up, and the request will
succeed. --Peter

That's technically correct, but the reason why this happens from a
design point of view is that the number of HTTP connections a client
can establish with any given host is limited by an URI's service point
(*). See System.Net.ServicePoint and System.Net.ServicePointManager for
more details.

(*) see http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8 for
more details.

Cheers,
 
Back
Top