WebSocket is a protocol which allows for communication between the client and the server/endpoint using a single TCP connection. The advantage WebSocket has over HTTP is that the protocol is full-duplex (allows for simultaneous two-way communcation).
Here is one simple example to create a WebSocket endpoint and communicate it from a client.
Java 1.7, Apache Tomcat, Eclipse
1. Create a Maven project with webapp archetype.
2.Create a WebSocket end point.
@ServerEndpoint annotation is used at type level and defines the current class as a websocket server endpoint. The value used in this annotation represents the URL where the endpoint will be listening for client connections
3. Create an html page
4. Build and deploy the war
Build the maven project and deploy the war in to tomcat server. Once the server is started hit the blow url.
We will see the connection established message in the screen, now enter your name and submit the request.
5. Download this example