Java Magazine, Jan/Feb 2016
Figure 2 Logging in to chat Figure 3 Chat in full flow ORACLE COM JAVAMAGAZINE JANUARY FEBRUARY 2016 54 web apps implementation scans the WAR file and finds all such classes and deploys them This means there is nothing special you have to do in order to get your server endpoints deployed except package them in the WAR file However you may wish to more tightly control which of a collection of server endpoints gets deployed in a WAR file In this case you may provide an implementation of the Java WebSocket API interface javax websocket ServerApplicationConfig which allows you to filter which of the endpoints get deployed The Chat Application A good way to test a push technology is to build an application that has frequent asynchronous updates to make to a number of interested clients Such is the case with a Chat application Lets take a look in some detail at how to apply what we have learned about the Java WebSocket API to build a simple chat application Figure 2 shows the main window of the Chat application which prompts for a username when you sign in Several people can be chatting all at once typing their messages in the text field at the bottom and clicking the Send Figure 4 Leaving chat button You can see the active chatters on the right side and the shared transcript recording everyones messages in the middle and left In Figure 3 there is an uncomfortable triad of people chatting In Figure 4 we can see that one of the chatters left rather suddenly and the other has left slightly more gracefully leaving just one chatter in the room
You must have JavaScript enabled to view digital editions.