JavaEE7 Websocket Example

In this tutorial I will try to present a very easy way to create a minimal Websocket Application using Java EE7.

The specific web application will have a working  Websocket Server deployable on every Java EE7 container plus a basic HTML5 page that will act as a client just to test your work.

Let’s get started then. The first thing that you will have to do is to create a web application. I used Netbeans IDE but you can do exactly the same thing using your IDE of preference or even just using maven and a text editor.

For those that use Netbeans go to -> New Project -> Maven -> Web Application. Give a name to your application and Select Java EE 7 Web.

The whole Websocket server will consist of 4 classes, the Message Class, the Encoder Class, the Decoder Class and the ServerEndpoint Class.

Here is the sample code for all 4 classes plus the HTML client:

Leave a Reply

Your email address will not be published. Required fields are marked *