Saturday, March 19, 2016

NetBeans Java EE Tip #6: Create WebSocket Endpoint

The introduction of WebSocket support with the release of Java EE 7 provided a means for utilizing full duplex communication in your Java EE applications.  To utilize WebSockets, one must create an endpoint to which the client can connect for communication purposes.  NetBeans provides an easy-to-use wizard for developing WebSocket endpoints with a few clicks.

1)  Create your endpoint class.  First, select "New"->"Web"->"WebSocket Endpoint":
Figure 1.  Select WebSocket Endpoint

2)  Next, name your endpoint accordingly, provide a package into which the endpoint will be created, and also provide a WebSocket URI.  This is the URI that the client will connect to in order to send a message.

Figure 2.  WebSocket Endpoint Generation

3)  The NetBeans IDE will generate the initial WebSocket endpoint code.  All that is left to do is implementation of the onMessage() method to suit your application.

I will show you how to easily generate a client to communicate with a WebSocket endpoint using NetBeans in a future Java EE tip!

No comments:

Post a Comment

Please leave a comment...