草庐IT

CloseHandler

全部标签

go - 如果我不在任何地方阅读消息,则不会为 gorilla /websocket 调用 CloseHandler,我最终只会收到写入错误

我有一个使用gorilla/websocket的websocket服务器。我有一种情况,我只是将消息写入一组websockets。当我在浏览器端关闭websocket时,我的自定义CloseHandler永远不会被调用。但是,添加无限期调用ReadMessage的goroutine(直到出现某些错误)会导致调用CloseHandler。基本思路如下:在一个goroutine中,我运行这样的东西:for{forclient:=rangeclients{client.stream和其他代码,在单独的goroutine中调用,每个客户端一个:go(func(){//IfIcallwsock.

go - 为什么超时直接关闭连接而不调用closeHandler方法?

为什么超时直接关闭连接而不调用closeHandler方法?ws.SetCloseHandler(func(codeint,textstring)error{fmt.Println("socketclose")}//cannotget"socketclose"stdout:"websocket:close1006(abnormalclosure):unexpectedEOF"包:“github.com/gorilla/websocket” 最佳答案 websocketRFC这是关于状态1006的:1006isareservedval

go - 为什么超时直接关闭连接而不调用closeHandler方法?

为什么超时直接关闭连接而不调用closeHandler方法?ws.SetCloseHandler(func(codeint,textstring)error{fmt.Println("socketclose")}//cannotget"socketclose"stdout:"websocket:close1006(abnormalclosure):unexpectedEOF"包:“github.com/gorilla/websocket” 最佳答案 websocketRFC这是关于状态1006的:1006isareservedval