WebSockets enable two-way communication between the user’s browser (the client) and a server. Normally, the server only responds to client requests. When using WebSockets, once the client has opened a connection with the server, the server can send messages to the client.
A good place to start learning about Websockets on the Web is with the Writing WebSocket client applications article on MDN web docs.
After reading this article, you should be able to:
onopen
event handler function to detect when the connection has been opened;onmessage
event handler function to detect and process messages sent by the server;onerror
event handler function to detect when an error has occurred;send()
method to send messages to the server;close()
method to close the connection to the server; andonclose
event handler function to detect when the connection to the server has been closed.