From the course: WebSocket Programming with Java EE

Unlock the full course today

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

WebSocket methodologies

WebSocket methodologies

From the course: WebSocket Programming with Java EE

Start my 1-month free trial

WebSocket methodologies

- [Instructor] The Java EE API for WebSocket is specified in JSR 356 and has a rich set of features. The WebSocket API provides two methodologies for implementing WebSocket endpoints. Programmatically, by extending the endpoint class and overriding its lifecycle methods. And by decorating in class with the appropriate annotations. The programmatic method represents an endpoint by instances of the endpoint class. The OnOpen method is overwritten and message handling logic is written. Two other lifecycle methods can be overwritten, onError and OnClose. And all the endpoints are registered and URI is defined in an application configuration class. And messages are sent by calling a send method on the client session. The annotation methodology is arguably much simpler, as all WebSocket configuration happens in the same class and is done by passing metadata to the appropriate annotation. So you annotate a class ServerEndpoint and specify the endpoint's URI. Optionally, you can specify a…

Contents