标签:deb socket async 域名 node ip地址 问题 delay add
苹果过审有一项是必须通过ipv6网络测试游戏,一开始的想法是实现两套socket链接,服务器也实现ipv6,后来百度了其实很简单,直接Dns.GetHostAddresses(string hostNameOrAddress)获取链接地址,hostNameOrAddress传域名地址,域名绑定服务器ip就好了,下面是完整代码:
//获取远端服务器ip地址
IPAddress[] address = Dns.GetHostAddresses(host);
if (address.Length == 0)
{
Debug.LogError("address.Length == 0");
return;
}
//判断当前网络是否为ipv6建立不同链接
if (address[0].AddressFamily == AddressFamily.InterNetworkV6)
{
client = new TcpClient(AddressFamily.InterNetworkV6);
}
else
{
client = new TcpClient(AddressFamily.InterNetwork);
}
//建立链接
client.NoDelay = true;
try {
client.BeginConnect(address[0], port, new AsyncCallback(OnConnect), null);
} catch (Exception e) {
Close(); Debug.LogError(e.Message);
}
标签:deb socket async 域名 node ip地址 问题 delay add
原文地址:http://www.cnblogs.com/ChengShuKaiShi/p/7750482.html