From the course: WebSocket Programming with Java EE

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Build the front end

Build the front end

From the course: WebSocket Programming with Java EE

Start my 1-month free trial

Build the front end

- [Instructor] Let's implement the WebSocket Client using HTML5 and JavaScript. So I open up the WebSocket Client JavaScript file which is located in the resources/js directory in the webapp folder. As you can see, there's quite a lot of code here already. This is jQuery code. It reacts to the users interactions and prints a received message to the screen. We're only concerned with writing the WebSocket functionality. So I won't discuss what's going on here. Now the first task is to create the connection to the WebSocket endpoint. For this we need the URL plus any path variables. Now in our application we have two path variables, the room name and the user name. So we need to obtain these values and append them to the end of the URL. Now I have a convenience method called constructURI that does just this job. So let's scroll down and have a look at this method. We just parseded the serviceLocation and the room name, and the user name, and it returns a correctly constructed URI. With…

Contents