In the original Echo sample application, a new WebSocket connection was created
code to establish the connection only once when the page loads for the first time. We
function will be called when a connection is made to our WebSocket server endpoint.
The onMessage() function will be invoked when the client receives a message from
the WebSocket server endpoint, and onError() will be invoked if there is an error
while communicating with the WebSocket server endpoint.
the corresponding functions in the Echo sample message; in our case, we modified
them to simply display a message on the browser log.
In most browsers, the browser console can be seen by hitting F12 and
clicking on the Console tab.
Our onMessage() function parses the JSON string sent by our WebSocket server
endpoint and populates our form with the appropriate values.
As far as the actual markup goes, we added a button labeled Get Defaults that
parameter. The doSend() function, in turn, passes this string to our WebSocket
WebSocket server endpoints returns a JSON string with default values when it
gets this exact string as a parameter.
The following screenshot shows our application in action: