The idea was to use HTML5 websocket API in the front end to communicate with websocket endpoint created in the glassfish server. To get started with I referred a similar sample application blogged by Arun Gupta.
In this process I managed to log following bugs against the reference implementation
- Session object coming as the parameter in @WebSocketClose annotated method is null
- Session#isOpen method returns NoSuchMethodException
To avoid this situation I have put the code "peer.getRemote().sendString("Ping");" in try block so that if it fails , it can gracefully remove that peer instead of ending up in exception.
My app lets you draw freehand lines in the browser and the same gets drawn in real time at every other user's browser who is accessing this app. If you refresh the page or a new user joins in then the existing state of the drawing is shown the browser.
To create such project one has to go maven way as of now. Following are the major steps you need to care about while creating this project
- Choose a Maven project in Netbeans
2. The Websocket Java APIs could not be imported in the Java class unless the websocket library is searched in the repository and added to the project
The source code that I created can be accessed from Github. Feel free to download and give feedback or try to create your own version.
You can download the slate demo video and play in any flash enabled browser.
Play this in full screen to see the code.
Further features and future challenges
- Different color and strokes
- Simultaneous drawing using webworkers.