HttpWebRequest and ServicePoint
Hi.
I have faced a problem that I still cannot find solution for.
I need to execute web requests to SAME web server using different source IP and port combinations. Yes, I know that I should use ServicePoint.BindIPEndPointDelegate and I use it. But my problem is that I have multi-threading application and because I use same destination address I got same ServicePoint instance for all threads and therefore can use only one combination of source IP and port in time.
Does anybody know solution to this problem?
I'm using .NET 2.0.
Thanks.
[557 byte] By [
dima_ua] at [2007-12-26]
The delegate will be called every time a connection is made on the HttpWebRequest socket.. It does not matter if its on the same ServicePoint because once the connection is made, this local endpoint can be changed.
For an example take a look at this article
http://blogs.msdn.com/malarch/archive/2005/09/13/466664.aspx
Thanks for reply.
I know that this bind delegate will be called and it's called. But you seems not understand my problem.
Imagine I have 10 threads and have 10 local IP addresses. I execute requests in parallel to 'www.microsoft.com' and I wont each thread to execute this request using it's own IP address.
Right now If I assign delegate it's called from all threads because ServicePoint instance to 'www.microsoft.com' is the same.
Is it clear?
Thanks for the idea. I've done the same already :)
But I still have question how to detect when IP address becomes free, e.g. when socket connection was closed, so I can return it to list of available IP addresses.
Interesting...
I'd also like to make use of different ip adresses for simultanuous http web requests to the same server. The idea behind it is that i fool the server, so i can make more concurrent requests than with only one ip address. Is this assumption right? Request are initiated from a LAN with firewall.
I have managed to make requests on different ports using the delegate specified. If i place another ip adddress in the delegate the request is not returned. Any ideas?
Thanks!
Well, not sure how to help you. In my case everything works fine. But I have a server that has direct Internet connection and it has pool of IP addresses (public IP) and I can make connections to same server using different IPs. Make sure you use correct local IP addresses.
Hmm, I think that answers my question. I do not have multiple public ip adresses - yet.
How did you solve your question "how to detect when IP address becomes free, e.g. when socketconnection was closed, so I can return it to list of available IP
addresses."
Could you please post some (pseudo) code, it would help a lot. Thanks!
Unfortunately I did not get response from MS guys and problem stills open. So basically I have a list of IP address and on ServicePoint bind get the IP from this list and place timestamp of "busy" flag, on the next ServicePoint bind I try to get next IP using this busy timestamp, so if last "busy" flag is >1 sec. I return this IP.
But I run into strange problem with ServicePoint bind that sometimes it was failing to perform bind (I did post here, but no answer). After investigating logs from System.Net it seems that I found where problem was - socket was disposed unexpectedly. What was the reason I still don't know. My workaround was to kill and re-create worker thread that started to fail on this.