What is the meaning of "ConnectEx tcp: The semaphore timeout period has expired."

huangapple go评论117阅读模式
英文:

What is the meaning of "ConnectEx tcp: The semaphore timeout period has expired."

问题

我写了一个简单的Go程序,在Windows上运行,测试远程端口是否活动:

package main
import (
    "fmt"
    "net"
)

func main(){
    conn, err := net.Dial("tcp", "192.168.23.191:3403")
    if err != nil {
        fmt.Println(err)
    } else {
        conn.Close()
    }
}

现在,远程端口是关闭的。第一次运行时,出现了错误:

dial tcp 192.168.23.191:3403: ConnectEx tcp: 远程计算机拒绝了网络连接。

然后我继续运行它,错误变成了:

dial tcp 192.168.23.191:3403: ConnectEx tcp: 信号量超时期已过。

为什么Dial返回"ConnectEx tcp: 信号量超时期已过"?这个错误的含义是什么?

英文:

I write a simple go program which runs on windows and tests whether the remote port is active:

package main
import (
    "fmt"
    "net"
)

func main(){
    conn, err := net.Dial("tcp", "192.168.23.191:3403")
    if err != nil {
	    fmt.Println(err)
    } else {
	    conn.Close()
    }
}  

Now, the remote port is closed. I run it first time, and the error is:

dial tcp 192.168.23.191:3403: ConnectEx tcp: The remote computer refused the network connection.  

Then I continue to run it, the error is changed to:

dial tcp 192.168.23.191:3403: ConnectEx tcp: The semaphore timeout period has expired.

Why the Dial returns "ConnectEx tcp: The semaphore timeout period has expired."? And what is the meaning of this error?

答案1

得分: 1

net.Dial()的调用超时了。

这里所示,Dialer结构体有一个Timeout字段,它定义了*Dial()等待连接完成的最长时间*。

英文:

The call to net.Dial() has a timeout which expired.

As seen here, the Dialer struct has a Timeout field which defines the maximum amount of time that a Dial() will wait for a connect to complete.

答案2

得分: 0

net.Dial(以及一些中间函数)最终调用了ConnectEx,这是Windows特定的BSD套接字扩展。如果连接无法建立(Windows遵循RFC 1122第4.2.3.5节并尝试多次),ConnectEx将失败并返回ERROR_SEM_TIMEOUT(据我所知,这并没有正式记录,人们可能期望得到类似WSAETIMEDOUT的错误)。因此,这个错误意味着端口关闭了。

在Windows 8及更高版本的Windows中,可以更改单个套接字的连接设置,如果你想在Go中进行这样的操作,你需要自己进行版本检查和调用。

英文:

net.Dial (with some intermediate functions) ends up calling ConnectEx, a Windows specific extension to BSD Sockets.
If the connection cannot be established (Windows conforms to RFC 1122 Section 4.2.3.5 and tries multiple times) ConnectEx fails with ERROR_SEM_TIMEOUT (AFAIK that isn't officially documented, one would expect an error like WSAETIMEDOUT).

So that error means that the port is closed.

On Windows 8 and newer Versions of Windows it is possible to change the connections settings for a single socket, if you want to do this in Go you have to do the version check and calls for yourself.

huangapple
  • 本文由 发表于 2014年3月4日 13:26:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/22163635.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定