websockettyrus

Tryus websocket client - onMessage does not get called although connection is succesful


I am successfully connecting to a local websocket server with tyrus, but the onMessage method does not get called. I setup Fiddler as proxy in between and I see that the server responds with two messages, however, they are not printed out in my code. I more or less adapted the sampe code:
The onOpen Message is printed out

public static void createAndConnect(String channel) {

    CountDownLatch messageLatch;
    try {
        messageLatch = new CountDownLatch(1);

        final ClientEndpointConfig cec = ClientEndpointConfig.Builder.create().build();
        ClientManager client = ClientManager.createClient();
        client.connectToServer(new Endpoint() {

            @Override
            public void onOpen(Session session, EndpointConfig config) {
                System.out.println("On Open and is Open " + session.isOpen());

                session.addMessageHandler((Whole<String>) message -> {
                    System.out.println("Received message: " + message);
                    messageLatch.countDown();
                });
            }
        }, cec, new URI("ws://192.168.1.248/socket.io/1/websocket/" + channel));
        messageLatch.await(5, TimeUnit.SECONDS); //I also tried increasing timeout to 30sec, doesn't help 
    } catch (Exception e) {
        e.printStackTrace();
    }

}

Web Socket response in Fiddler


Solution

  • That's a known issue - it will work if you rewrite lambda to anonymous class or use Session#addMessageHandler(Class, MessageHandler) (you can use lambdas here).