Developing JavaScript client-side WebSocket code

In this section, we will cover how to develop client-side JavasScript code to interact with the WebSocket endpoint we developed in the previous section.

The client page for our WebSocket example is implemented as a JSF page using HTML5 friendly markup (as explained in Chapter 2, JavaServer Faces).

Our client page consists of a text area, where we can see what users of our application are saying (it is, after all, a chat application), and an input text we can use to send a message to other users:

The markup for our client page looks like this:

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE ...

Get Java EE 8 Application Development 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.