Spring boot + Websockets : Connection getting closed by itself.

Problem : Getting the message “Websocket already in CLOSED or CLOSING state” from browser console after sending the first message.

Reason: The packet size is larger than the one set for Text/Binary message on Spring WebSocket handler.

Fix: Increase size limit for individual packages/frames in the Spring handler –

 @Override
    public void afterConnectionEstablished(WebSocketSession session) throws Exception {
        session.setTextMessageSizeLimit(1024 * 1024);
        session.setBinaryMessageSizeLimit(1024 * 1024);
        log.info("Connection established");
    }

Leave a Reply

Your email address will not be published. Required fields are marked *

*

* Copy This Password *

* Type Or Paste Password Here *

45,334 Spam Comments Blocked so far by Spam Free Wordpress

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>