c# - Unable to connect to the remote server when selecting IpEndPoint -


I have a code running on a computer with several IP address, and I got the code to choose an IP Address for a httpWebRequest:

  class interaction {& lt; Data, cookies, etc. & gt; HttpWebRequest CreateWebRequest (...) {..... request.ServicePoint.BindIPEndPointDelegate = Representative (ServicePoint ServicePoint, IPEndPoint Remote EndPoint, Int Retrieval) {if (lastIpEndpoint! = Null) {lastEppointpoint Return; } Var candidate = GetAddresses (Remote EndPoint.AddressFamily); If (Candidates == Null) candidates Number () == 0) {throwing new non-implemented exceptions; } Previous End IPDpoint = New IPPpoint (Candidates [RD Next (Candidates No. ()), 0); }; }; Return request; }}   

Here is the code for GetAddresses:

  static IPAddress [GetAddresses (Address Family af) {System.Net.IPHostEntry _IPHostEntry = System.Net . Dns.GetHostEntry (System.Net.Dns.GetHostName ()); Return (i _IPHostEntry.AddressList from where i.AddressFamily == af select i) .oir (); }   

This code is supposed to choose a random IP from the available IP list, and with its stick.

Instead, every time I send a request with it, I

Unable to connect to the remote server

I How do I do this work?

It seems that you are setting the port number of the zero end point in the row:

  lastIpEndpoint = new IPPpoint (candidates [candidates] (candidates number ()), 0);   

As long as it will change later, it is not possible that you will be able to connect to an HTTP server on port 0. You may be able to use the port contained in .

  Last AutoPoint = New IPPpoint (Candidates [Rnd. Next (Candidates number ()), Remote EndPoint.port;    

Comments