大猩猩WebSocket WriteMessage错误 – Go语言

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

Gorilla WebSocket WriteMessage errors - Go Lang

问题

如果使用WriteMessage发送消息时返回了错误,你可以考虑以下几种处理方式:

  1. 如果错误是由于连接问题导致的,你可以开始进行关闭握手,以确保连接的正常关闭。

  2. 如果你认为错误可能会在使用ReadMessage方法时被捕获到,你可以简单地记录错误日志,而不进行关闭握手。

具体选择哪种方式取决于你的需求和应用场景。你可以根据具体情况来决定如何处理错误。

英文:

I am currently experimenting with Gorilla WebSocket package. When sending a message using WriteMessage, if an error is returned, what should I do? Should I start the Closing Handshake or assume that if there is a problem it will be caught using the ReadMessage method and simply log the error?

答案1

得分: 2

如果WriteMessage返回错误,则应用程序应关闭连接。这将释放连接使用的资源,并导致读取器返回错误。

在WriteMessage返回错误后,无法发送关闭握手。如果WriteMessage返回错误,则所有后续的写操作也将返回错误。

英文:

If WriteMessage returns an error, then the application should close the connection. This releases resources used by the connection and causes the reader to return with an error.

It is not possible to send a closing handshake after WriteMessage returns an error. If WriteMessage returns an error, then all subsequent writes will also return an error.

huangapple
  • 本文由 发表于 2016年2月12日 05:11:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/35350101.html
匿名

发表评论

匿名网友

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

确定