Websocket onerror - how to read error description?

前端 未结 2 678
庸人自扰
庸人自扰 2020-12-07 18:13

I\'ve been developing browser-based multi player game for a while now and I\'ve been testing different ports accessibility in various environment (client\'s office, public w

2条回答
  •  温柔的废话
    2020-12-07 18:51

    The error Event the onerror handler receives is a simple event not containing such information:

    If the user agent was required to fail the WebSocket connection or the WebSocket connection is closed with prejudice, fire a simple event named error at the WebSocket object.

    You may have better luck listening for the close event, which is a CloseEvent and indeed has a CloseEvent.code property containing a numerical code according to RFC 6455 11.7 and a CloseEvent.reason string property.

    Please note however, that CloseEvent.code (and CloseEvent.reason) are limited in such a way that network probing and other security issues are avoided.

提交回复
热议问题