Events fired by Websocket Instances

The events that a WebSocket object instance fires are:

EventDescription
opencalled when the connection has been opened
messagecalled when a message has been received from the server
errorcalled when an error occurs with the socket (sending or receiving)
closecalled when the connection is closed

For each of these events, you can add an event listener using addEventListener(...), or you can set a corresponding handler directly on the worker object instance, including onopen, onmessage, onerror and onclose.

If Web Sockets are not supported, you’ll need to provide some fallback functionality for your application, or at least gracefully notify the user that their browser doesn’t support the required functionality.

Note:
Notes
Because consistent browser support for Web Sockets is minimal, the best practice suggestion for using Web Sockets is to use a library like Socket.io (http://socket.io/), which attempts to use Web Sockets if available, and falls back to a variety of other techniques for communication if Web Sockets are not present.
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 # # # # #