0

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?

bcsb1001
  • 2,834
  • 3
  • 24
  • 35
Trigon219
  • 149
  • 1
  • 4
  • I think you have connected, a 404 implies that `/MyJavaWebSocket/MyEndPoint` could not be found however, can you verify that the endpoint is correct? – Shaun Wild Jul 08 '16 at 16:18
  • Yes, the endpoint is correct because, with the private IP it works, so the only thing that I changed was the IP, from private to public. – Trigon219 Jul 08 '16 at 16:34
  • 190.168.10.10:8083 doesn't seem to be reachable as a public IP address from the public internet – jfriend00 Jul 08 '16 at 18:26
  • Sorry i changed the real ip for security reasons. – Trigon219 Jul 11 '16 at 12:51

0 Answers0