SEND WEBSOCKET MESSAGES

After you have created a WebSocket client framework, you can begin to tie outgoing messages as soon as the onOpen() function has started. This function will be run by the open event, after the connection handshake process is complete, indicating that a connection is active.

Because WebSockets are a full-duplex protocol, you can technically send a WebSocket message at any time to the server, after, that is, you have established a successful connection, of course. There is not much point in limiting your outgoing messages to only the onOpen() function, unless the WebSocket service does not require any additional messages.

Therefore, you need a way to be able to send commands, but only while online. This is accomplished by ...

Get HTML5: Your visual blueprint™ for designing rich web pages and applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.