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 –
[java]
@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
session.setTextMessageSizeLimit(1024 * 1024);
session.setBinaryMessageSizeLimit(1024 * 1024);
log.info("Connection established");
}
[/java]