Finally I figured this out. So I am answering here for others to refer.
1)How will I use this annotation in servlets? Are servlets irrelevent in case of web sockets?
Apparently yes, we don't need servlets for web sockets.
2)If I create a normal class with the above annotation, and other annotation like onOpen,onClose etc, should I need to put the entry for that class in web.xml? Or are web.xmls are irrelevant too?
No entry needed in web.xml either.
Following, is a sample server side code.
@ServerEndpoint(value = "/echo")
public class Echo {
@OnOpen
public void start(Session session) {
//TODO
}
@OnClose
public void end() {
//TODO
}
@OnMessage
public void incoming(String message) {
//TODO
}
@OnError
public void onError(Throwable t) throws Throwable {
//TODO
}
}
For client, either you can use Javascript is you have a HTML5 compatible browser. Else you write java clients using the tyrus library. Refer here