I am trying to create a web socket in java. However I am getting error "Error during WebSocket handshake: Unexpected response code: 404 (anonymous)" when I am trying to connect to the socket using java script.
I have tried using provided scope with the javax.websocket, also tried switching to tomcat7-websocket jar as suggested in answers here WebSocket 404 error . I am still getting the same error. Thank you for the help in advance.
I also tried removing the .m2 directory, that didn't help either.
I am using this code on java end
@ServerEndpoint("/webSockTest")
public class ServerTest {
private static Set<Session> peers = Collections.synchronizedSet(new HashSet<Session>());
@OnOpen
public void open(Session session) {
peers.add(session);
}
@OnClose
public void close(Session session) {
peers.remove(session);
}
@OnError
public void onError(Throwable error) {
}
@OnMessage
public String handleMessage(String message, Session session) {
return "hello";
}
}
And trying to connect using:
new WebSocket("ws://localhost:8080/demo/webSockTest")