HTML and CSS Reference
In-Depth Information
p.textContent = s;
output.appendChild(p);
// Also log information on the javascript console
console.log(s);
}
// Start running the example.
setup();
</script>
After running the web page, the output should look similar to the following:
WebSocket Sample Client
Connected
Message sent
Message received: Hello WebSocket!
Disconnected
If you see this output, congratulations! You've successfully created and executed
your first sample WebSocket client application. If the example does not work, you'll need
to investigate why it has failed. You may find useful information in the JavaScript console
of your browser. It is possible, though increasingly unlikely, that your browser does not
support WebSocket. While the latest versions of every major browser contain support for
the WebSocket API and protocol, there are still some older browsers in use that do not have
this support. The next section shows you how to ensure your browser supports WebSocket.
Checking for WebSocket Support
Since (surprisingly) not all web browsers support WebSocket natively yet, it's good
practice to include in your code a way to determine the browser support and, if possible,
provide a fallback. Most modern browsers support WebSocket, but depending on your
users, you'll likely want to use one of these techniques to cover your bases.
Note
Chapter 8 discusses various WebSocket fallback and emulation options.
 
 
Search WWH ::




Custom Search