我有如下代碼:_, err := websocket.Dial("wss://remote-server", "", "http://localhost")if (err == nil) { fmt.Println("Worked!")} else { fmt.Println("Fail")}當remote-serverdown 時,需要 60s 超時。我找到了websocket.SetDeadline(http://godoc.org/code.google.com/p/go.net/websocket#Conn.SetDeadline),但我還沒有將它應用到的連接。我可以傳遞一個Configto DialConfig,但我看不到在哪里指定超時。我找到了https://code.google.com/p/go-wiki/wiki/Timeouts,這是我必須做的嗎?如何正確地從 goroutine 傳回錯誤代碼?
1 回答

largeQ
TA貢獻2039條經驗 獲得超8個贊
我還沒有使用 go websocket 包,但從我可以從文檔中推斷出,應該使用net.DialTimeout(...)和websocket.NewClient(...)
DialConfig的源使用相同的方法,但僅限于 net.Dial。
- 1 回答
- 0 關注
- 377 瀏覽
添加回答
舉報
0/150
提交
取消