写了一个socks5代理检查功能 编译成dll给其他语言调用
发现前500连接正常返回 后面直接报错
请问怎样解决?
err:Get http://api.guajicun.com/getip/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
================分割线==================
func main() {
for i := 0; i < 1000; i++ {
go Socks5Tcp("xxx", "user", "user", 3000)
}
}
func Socks5Tcp(host, user, pass string, out int) string {
// create a socks5 dialer
dialer, err := proxy.SOCKS5("tcp", host, &proxy.Auth{user, pass}, proxy.Direct)
if err != nil {
return fmt.Sprintf("error:%v", err)
}
// setup a http client
httpTransport := &http.Transport{}
httpClient := &http.Client{Transport: httpTransport, Timeout: time.Millisecond * time.Duration(out)}
// set our socks5 as the dialer
httpTransport.Dial = dialer.Dial
resp, err := httpClient.Get("http://api.guajicun.com/getip/")
if err != nil {
return fmt.Sprintf("error:%v", err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return fmt.Sprintf("error:%v", err)
}
// success
return fmt.Sprintf("success:%s", body)
}
有疑问加站长微信联系(非本文作者)