From the course: Learning Java Enterprise Edition

Unlock the full course today

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

WebSocket in practice

WebSocket in practice - Java EE Tutorial

From the course: Learning Java Enterprise Edition

Start my 1-month free trial

WebSocket in practice

- [Narrator] We are now going to take a look at how WebSockets are used in practice, and in particular how we are using them in the CargoTracker application. Okay, so let's get started. So returning to the live map we can view its source to discover the HTML that contains the call to the WebSocket URI. You will notice that we are creating a new WebSocket object. This is actually part of the HTML5 itself. On the client side we have to implement very similar call-back methods to those that we implement on the server side. This is something that we'll have a look at in a moment. Here we have implemented an onopen, onmessage, onclosed that are called when the connection is made. The message is received and the connection is closed respectively. Now let's turn our attention to the server-side code. I'm going to open the RealtimeCargoTrackingService class. You might remember this class from the previous video. Here you can see that we are using the annotational way to write WebSockets. And…

Contents