小编rox*_*rox的帖子

为什么net.DialTimeout一半的时候会超时?

这是我的测试代码,我设置了6s超时,但是程序只执行了3s,为什么?

package main

import "net"
import "time"
import "fmt"

func main() {
    fmt.Println(time.Now())
    conn, err := net.DialTimeout("tcp", "google.com:80",6*time.Second) // chinese people can't access google
    fmt.Println(time.Now())
    fmt.Println(conn,err)
}
Run Code Online (Sandbox Code Playgroud)

测试结果:

2016-05-18 16:21:31.325340213 +0800 CST
2016-05-18 16:21:34.32909193 +0800 CST
<nil> dial tcp 59.24.3.173:80: i/o timeout
Run Code Online (Sandbox Code Playgroud)

go

9
推荐指数
1
解决办法
1万
查看次数

标签 统计

go ×1