I'm doing a websocket with javax.websocket and a JavaScript client; when I call the websocket in JavaScript with a private IP it works, like this:
var websocket = new WebSocket("ws://10.3.3.25:8083/MyJavaWebSocket/MyEndPoint");
But when I try to change the IP for a public IP, it doesn't work:
var websocket = new WebSocket("ws://190.168.10.10:8083/MyJavaWebSocket/MyEndPoint");
or
var websocket = new WebSocket("ws://mydomain.com:8083/MyJavaWebSocket/MyEndPoint");
It throws "failed: Error during WebSocket handshake: Unexpected response code: 404".
This is my Java server code:
@ServerEndpoint(value = "/MyEndPoint", configurator = ChatServerEndPointConfigurator.class)
public class MyEndPoint {
static Set<Session> sesionesUsuarios = Collections.synchronizedSet(new HashSet<Session>());
@OnOpen
public void onOpen(Session session) {
sesionesUsuarios.add(session);
System.out.println(session.getId() + " has opened a connection");
try {
session.getBasicRemote().sendText("Connection Established");
} catch (IOException ex) {
ex.printStackTrace();
}
}
@OnMessage
public void onMessage(String message, Session session) {
session.getBasicRemote().sendText("SEND MESSAGE");
}
@OnClose
public void onClose(Session session) {
sesionesUsuarios.remove(session);
System.out.println("Session " + session.getId() + " has ended");
}
@OnError
public void onError(Throwable e) {
e.printStackTrace();
}
}
I'm using apache-tomcat-8.0.33. Can anyone help shed some light on what is wrong here?