Is onclose always called after onerror for WebSocket

The error event will only ever be fired prior to then also firing the close event, at least by implementations that properly implement the specification, i.e. you will get error and close as a pair, or just close by itself.

The process for closing a websocket consists of 3 steps, the second of which optionally fires the error event if needed:

  1. If the user agent was required to fail the WebSocket connection, or if the the WebSocket connection was closed after being flagged as full, fire a simple event named error at the WebSocket object. [WSP]

Before the third step then calls close:

  1. Fire an event named close at the WebSocket object, using CloseEvent,…

And because both of these steps are one after the other inside the same queued task, your event handlers should be invoked one after the other, with no other events or tasks taking place in between them.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)