Play Framework 2.5.x Web Socket Java

I follow the instructions in the official documentation of the Play Framework 2.5.x for Java Websockets, I created a controller with this function

public static LegacyWebSocket<String> socket() {
    return WebSocket.withActor(MyWebSocketActor::props);
}

And the Actor class MyWebSocketActor:

   public class MyWebSocketActor extends UntypedActor {

    public static Props props(ActorRef out) {
        return Props.create(MyWebSocketActor.class, out);
    }

    private final ActorRef out;

    public MyWebSocketActor(ActorRef out) {
        this.out = out;
    }

    public void onReceive(Object message) throws Exception {
        if (message instanceof String) {
            out.tell("I received your message: " + message, self());
        }
    }
}

Then the application is launched. I am trying to connect to ws: // localhost: 9000, as written in the official documentation:

Tip. You can check your WebSocket controller at https://www.websocket.org/echo.html . Just set the location to WS: // local :. 9000

But the web socket seems unreachable, how can I check it?

thank

+4
source share
2 answers

WebSocket, routes .

GET /ws controllers.Application.socket()

WebSocket ws://localhost:9000/ws - -.

+2

, ! -: socket()

public LegacyWebSocket<String> socket() {
        return WebSocket.withActor(MyWebSocketActor::props);
    }

socket()

GET     /ws                          controllers.HomeController.socket()

SSL/TLS , :

activator run -Dhttps.port=9443

websocket.org/echo.html wss://localhost:9443/ws Location websocket!

, https://localhost:9443/ws,

WebSocket

+2

All Articles