@StewartBW , Welcome to Microsoft Q&A,in .NET, WebClient doesn't directly support connecting via a specific IP address and port. If you need to connect to a specific IP address and port, you typically use other classes like HttpWebRequest.
Here is a code example you could refer to:
Sub Main()
Dim request As HttpWebRequest = CType(WebRequest.Create("http://MyServer"), HttpWebRequest)
request.ServicePoint.BindIPEndPointDelegate = New BindIPEndPoint(AddressOf BindIPEndPointCallback)
Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
End Sub
Public Function BindIPEndPointCallback(ByVal servicePoint As ServicePoint, ByVal remoteEndPoint As IPEndPoint, ByVal retryCount As Integer) As IPEndPoint
Console.WriteLine("BindIPEndpoint called")
Return New IPEndPoint(IPAddress.Any, 5000)
End Function
Best Regards,
Jack
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.