public void StartClick() { // vip vport area print("StartClick"); string domainStr = domain.text; print(domainStr); if (domainStr == null || domainStr.Equals("")) { domainStr = "www.qq.com"; print("输入为空,使用默认域名:www.qq.com"); result.text = "输入为空,使用默认域名:www.qq.com"; } string ips = HttpDns.GetHostByName(domainStr); print(ips); string[] sArray = ips.Split(new char[] { ';' }); if (sArray != null && sArray.Length > 1) { if (!sArray[1].Equals("0")) { //使用建议:当ipv6地址存在时,优先使用ipv6地址 //TODO 使用ipv6地址进行连接,注意格式,ipv6需加方框号[ ]进行处理,例如:http://[64:ff9b::b6fe:7475]/ result.text = "ipv6地址存在:" + sArray[1] + ",建议优先使用ipv6地址,注意格式,需加方框号加[]处理!"; } else { //使用ipv4地址进行连接 result.text = "ipv6地址不存在,使用ipv4地址进行连接:" + sArray[0]; } } }
public void onDnsNotify(string ipString) { print(ipString); string[] sArray = ipString.Split(new char[] { ';' }); if (sArray != null && sArray.Length > 1) { if (!sArray [1].Equals("0")) { //使用建议:当ipv6地址存在时,优先使用ipv6地址 //TODO 使用ipv6地址进行连接,注意格式,ipv6需加方框号[ ]进行处理,例如:http://[64:ff9b::b6fe:7475]/ result.text = "ipv6 address exist:" + sArray [1] + ", suggest to use ipv6 address."; } else if (!sArray [0].Equals("0")) { //使用ipv4地址进行连接 result.text = "ipv6 address not exist, use the ipv4 address:" + sArray [0] + " to connect."; } else { //异常情况返回为0,0,建议重试一次 print("ReStartSyncClick"); print(domainStr); if (domainStr == null || domainStr.Equals("")) { domainStr = "www.qq.com"; print("input is null, use the default domain:www.qq.com."); result.text = "input is null, use the default domain:www.qq.com."; } HttpDns.GetAddrByNameAsync(domainStr); } } }
public void StartAsyncClick() { // vip vport area print("StartAsyncClick"); string domainStr = domain.text; print(domainStr); if (domainStr == null || domainStr.Equals("")) { domainStr = "www.qq.com"; print("input is null, use the default domain:www.qq.com."); result.text = "input is null, use the default domain:www.qq.com."; } HttpDns.GetHostByNameAsync(domainStr); }
public void StartClick() { print("WGGetHostByName StartClick"); string domainStr = domain.text; print(domainStr); if (domainStr == null || domainStr.Equals("")) { domainStr = "www.qq.com"; print("输入为空,使用默认域名:www.qq.com"); result.text = "输入为空,使用默认域名:www.qq.com"; } // 使用子线程来调用HttpDns耗时解析接口 string ips = null; Thread thread = new Thread(new ThreadStart(() => { ips = HttpDns.GetHostByName(domainStr); print("WGGetHostByName result ips are " + ips); })); thread.Start(); #if UNITY_ANDROID result.text = ips; #endif #if UNITY_IOS string[] sArray = ips.Split(new char[] { ';' }); if (sArray != null && sArray.Length > 1) { if (!sArray[1].Equals("0")) { //使用建议:当ipv6地址存在时,优先使用ipv6地址 //TODO 使用ipv6地址进行连接,注意格式,ipv6需加方框号[ ]进行处理,例如:http://[64:ff9b::b6fe:7475]/ result.text = "ipv6地址存在:" + sArray[1] + ",建议优先使用ipv6地址,注意格式,需加方框号加[]处理!"; } else { //使用ipv4地址进行连接 result.text = "ipv6地址不存在,使用ipv4地址进行连接:" + sArray[0]; } } #endif }
public void Awake() { HttpDns.Init(); }
public string GetHostWithHttpDns(string url) { return(HttpDns.GetHostByName(url)); }