Java EE 7 SDK |
This sample application consists of a drawing board shared among several users with real-time change propagation.
This sample demonstrates the main advantage of the Java API for WebSocket (JSR 356) compared to other technologies based on the HTTP protocol: bi-directional real-time communication. When you deploy this application and load its front page, the changes you make to the canvas are propagated to all connected clients. The whole state is not propagated: if the first users draws a smiley face and the second user joins right after, this second user only sees a bank canvas. But when the second user starts drawing something, the first user sees it immediately.
This sample application demonstrates the following key features:
Creating a WebSocket server endpoint and registering methods to handle endpoint events using the following annotations:
@ServerEndpoint
@OnMessage
@OnOpen
@OnClose
Perform the following steps to build, deploy, and run the application:
app_dir
is the sample application base directory: samples_install_dir/javaee7/websocket/draw
.run
outcome.
mvn clean verify cargo:run
http://localhost:8080/websocket-draw
.clean
outcome to undeploy the sample application and to remove the temporary directories such as build
and dist
.
mvn clean
If you have problems when running the application, refer to the troubleshooting document.
Copyright © 1997-2013 Oracle and/or its affiliates. All rights reserved.