private sub hs_call() winsk1.remotehost = "188.188.188.8 " winsk1.remoteport = 6666 if winsock1.state <> sckclosed then winsock1.close end if winsock1.connect doevents end sub 以上是winsock的常见的客户端连接,当connect的ip地址存在的时候,握手正常一般只要1-2秒,当connect的ip存在,但握手不正常,返回错误信息的时间也只要2-5秒,但是当所connect的ip不存在,比如192.168.1.6或以上ip在内网不存在,那么返回错误信息的时间就要50秒左右。 问题是怎么缩短ip不存在时的返回时间?50秒也太久了。
可以指定其多几次连接,以前我就是这么做的,效果不错,也就几秒。 改写你的代码如下: private sub hs_call() dim j, itrytimes as ingteger winsk1.remotehost = "188.188.188.8 " winsk1.remoteport = 6666 if winsock1.state <> sckclosed then winsock1.close end if
j = 0 itrytimes =128 '设定试图连接的次数 with winsk1 do doevents if .state = 7 then exit do '如果连上就退出 j = j + 1 if .state <> 6 and j mod 16 = 0 then '处于“正在连接”或“关闭”状态 .close doevents .remotehost = "188.188.188.8 " .remoteport = 6666 .protocol = scktcpprotocol .connect end if if j > itrytimes then exit do ' loop end with
end sub
发表于:2007-07-23 19:13:2813楼 得分:0
if .state <> 6 and j mod 16 = 0 then '处于“正在连接”,且循环了16次