Reputation: 4127
I have code like the following:
_, err := websocket.Dial("wss://remote-server", "", "http://localhost")
if (err == nil) {
fmt.Println("Worked!")
} else {
fmt.Println("Fail")
}
When remote-server
is down, it takes 60s to timeout. I found websocket.SetDeadline
(http://godoc.org/code.google.com/p/go.net/websocket#Conn.SetDeadline), but I don't have a connection yet to apply it to. I can pass a Config
to DialConfig
, but I can't see where to specify a timeout doing that.
I found https://code.google.com/p/go-wiki/wiki/Timeouts, is this how I have to do it? How do I correctly pass the error code back from the goroutine?
Upvotes: 4
Views: 1661
Reputation: 7639
I havent used the go websocket package yet but from what I can infer from the documentation one should probably use net.DialTimeout(...) coupled with websocket.NewClient(...)
The source of DialConfig uses the same method but limited to net.Dial.
Upvotes: 2