var targetHostAddress = "http://myStagingSubDomain.cloudapp.net";
var ipAddresses = Dns.GetHostAddresses(targetHostAddress); <-- exception was being thrown here...
var ipAddress = ipAddresses[0];
using (var client = new TcpClient())
{
client.Connect(ipAddress, port);
Console.WriteLine("{0}Connected to {1}:{2}.", Environment.NewLine, ipAddress.ToString(), port.ToString());
}
The Exception:
var targetHostAddress = "localhost"; // "{substitute_your_windows_azure_host_name_instead_here--don't_include_the_protocol_or_trailing_slash}";
var ipAddresses = Dns.GetHostAddresses(targetHostAddress);
var ipAddress = !targetHostAddress.Contains("localhost") ? ipAddresses[0] : ipAddresses[1];
... notice the host name test in the 3rd line? That's important (at least in my office anyway...), because ipAddress[0] was actually "::1", NOT "127.0.0.1" like I expected. For the life of me I couldn't figure out why I kept getting that exception until I added a few more breakpoints. Never assume that would should be is... trust, but verify.
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)