Dns.GetHostByName(string)已过时问题解决方法

“System.Net.Dns.GetHostByName(string)”已过时之类问题解决总结
程序出现: 警告 1 “System.Net.Dns.GetHostByName(string)”已过时:“GetHostByName is obsoleted for this type, please use GetHostEntry instead. http://go.microsoft.com/fwlink/?linkid=14202
当从VS2003升级到vs2005,或者vs2005到vs2008,vs2010,经常遇到一些警告过时,此类问题解决主要看提示:GetHostByName is obsoleted for this type, please use GetHostEntry instead. GetHostByName类型已经过时,请用GetHostEntry代替,其它类似问题都可以这样解决。只需要将GetHostByName换成GetHostEntry即可。

例如:

//using System.Net;

string hostName = System.Net.Dns.GetHostName();

this.textBox1.Text = hostName;//获取主机名称
System.Net.IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(hostName);

//Dns.GetHostByName(hostName);          
//ip地址列表
System.Net.IPAddress[] addr = ipEntry.AddressList;
string IPAddress = addr[0].ToString();
this.textBox2.Text = IPAddress;

service->sin_addr.s_addr = inet_addr(hostname); if (service->sin_addr.s_addr == INADDR_NONE) { struct hostent *host = gethostbyname(hostname); if (host == NULL || host->h_addr == NULL) { RTMP_Log(RTMP_LOGERROR, "Problem accessing the DNS. (addr: %s)", hostname); ret = FALSE; goto finish; } service->sin_addr = *(struct in_addr *)host->h_addr; } 上面是代码的一部分,现在出现这个报错, INFO: ....RTMP chn [0] CONNECT........... ERROR: RTMP chn [0] ONLINE, try to connect. connecttimes: 4 [Error]2025-10-13/14:46:25-567 preview_simple_add_batch_auth: Unauth Channel: 0 / 2. Try next time. PreviewPage.c:1178 [cloud-brd](tid3069517824)1760337987192|2305|4|cloud_ip_list.c:56:cloud_ip_list_parse| - get addr info error, host:n-device-sur.tplinkcloud.com, serv:443, Name or service not known [cloud-brd](tid3069517824)1760337987192|2305|4|cloud_session.c:1515:cloud_session_connect_defaultSvr| - fail to get ip [cloud-brd](tid3069517824)1760337987192|2305|4|cloud_session.c:665:cloud_session_active_long_time| - fail to connect the defaultSvr, result:-4 [Error]2025-10-13/14:46:30-568 preview_simple_add_batch_auth: Unauth Channel: 0 / 2. Try next time. PreviewPage.c:1178 [Error]2025-10-13/14:46:35-572 preview_simple_add_batch_auth: Unauth Channel: 0 / 2. Try next time. PreviewPage.c:1178 [Error]2025-10-13/14:46:40-572 preview_simple_add_batch_auth: Unauth Channel: 0 / 2. Try next time. PreviewPage.c:1178 [Error]2025-10-13/14:46:45-573 preview_simple_add_batch_auth: Unauth Channel: 0 / 2. Try next time. PreviewPage.c:1178 [Error]2025-10-13/14:46:50-577 preview_simple_add_batch_auth: Unauth Channel: 0 / 2. Try next time. PreviewPage.c:1178 ERROR: Problem accessing the DNS. (addr: ns8.indexforce.com) ERROR: RTMP chn [0] enter recon_protection mode. [Error]2025-10-13/14:46:55-578 preview_simple_add_batch_auth: Unauth Channel: 0 / 2. Try next time. PreviewPage.c:1178 INFO: ....RTMP chn [0] CONNECT........... 而且这两次INFO: ....RTMP chn [0] CONNECT...........之间花了30s,你帮我看看这上面的代码哪里导致阻塞的
10-14
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值