We have been building a iOS app that is about Client - Server App. We are using an SQL connection and WCF web services in the iOS app with Xamarin.
SQL Connection Code :
There's already some helpful stuff in the comments, but I think that your main problem is that you had the IPv4 to IPv6 mapping the other way around. You were leaving the IPv4 address as it was and mapping the IPv6 address to IPv6 which it already was.
Take a look at the fixed version:
string input = "10.0.0.0";
string ips = "";
IPAddress address;
if (IPAddress.TryParse(input, out address))
{
switch (address.AddressFamily)
{
case System.Net.Sockets.AddressFamily.InterNetwork:
// we have IPv4, map it to IPv6
IPAddress ip = IPAddress.Parse(input).MapToIPv6();
ips = ip.ToString();
break;
case System.Net.Sockets.AddressFamily.InterNetworkV6:
// we have IPv6, leave it as is
ips = input;
break;
}
}
To see for yourself, you can take a look at the Reference Source. From there you see that in your example the AddressFamily
was InterNetworkV6
so the MapToIPv6
method just returns the IPAddress
unchanged because there's nothing to change.
public IPAddress MapToIPv6()
{
if (AddressFamily == AddressFamily.InterNetworkV6)
{
return this;
}
// ...
}
Have it resolved? You shouldn't care about AddressFamily of device,just care about remote ip AddressFamily .
IPAddress ip = IPAddress.Parse(input);
Socket s = new Socket (ip.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
I used it, and it works.
Change your server IP: 10.0.0.0 to the domain name, such as db.test.com, it's Apple's recommended approach.
string input = "db.test.com";
IPAddress[] ads = Dns.GetHostAddresses (input);
string ips = ads[0];