我想减少套接字:连接将查找一个IP /端口连接到允许的timeOut时间?在一些像Netgear这样的使用IP 10.0.0.x的网络路由器上,超时只需不到一秒的时间。套接字:连接将花费2分钟时间寻找IP在它之前。如何减少这段时间?
注:“选择”是后
host = gethostbyname("xxx");//invalid IP,
memcpy(&(sin.sin_addr), host->h_addr, host->h_length);
sin.sin_family = host->h_addrtype;
sin.sin_port = htons(4000);
s = socket(AF_INET, SOCK_STREAM, 0);
hConnect = connect(s, (struct sockaddr*)&sin, sizeof(sin));//sits here for 2 minutes before moving on to the next line of code
bConn = 0;// no connect
if (hConnect == 0) {
bConn = 1;// connect made
}
THX
您使用什么操作系统连接()
这里有一个有趣的异步方法:http://stackoverflow.com/q/1062035/694576 – alk
我正在使用一个标准C库...这在PC或MAC或iPhone上重复 – jdl