dongmei9020 2016-02-14 11:57
浏览 552

WebSocket何时使用关闭握手

I'm experimenting with Gorilla WebSocket Package and I would like to know whether there is a way based on the error retrieved from .ReadMessage to determine whether to start the Closing Handshake (ex. 1000 - normal closure) or stop the connection immediately (ex. 1006 - abnormal closure).

Currently what I'm doing is to store the list of error codes that I might use to close the websocket connection and if an error code is equals to one of the codes in my list, I do the Closing Handshake. However I'm not sure whether this complies with the WebSocket Spec.

Is there another way to do this or this is how it is suppose to be done?

  • 写回答

1条回答 默认 最新

  • dongzhe3573 2016-02-14 13:40
    关注

    Applications should only send close frames when the application decides to close the connection. The Gorilla package handles all other cases.

    The Gorilla package sends the closing handshake on read errors. The Gorilla internal method handleProtocolError starts the closing handshake.

    Gorilla replies to closing handshakes from the peer application.

    评论

报告相同问题?

悬赏问题

  • ¥15 为什么我按照电路图做出的仿真和实物都不能使用
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面
  • ¥15 算法题:数的划分,用记忆化DFS做WA求调
  • ¥15 chatglm-6b应用到django项目中,模型加载失败
  • ¥15 CreateBitmapFromWicBitmap内存释放问题。
  • ¥30 win c++ socket
  • ¥15 C# datagridview 栏位进度
  • ¥15 vue3页面el-table页面数据过多
  • ¥100 vue3中融入gRPC-web