I have used spring implementation of sockjs websocket server and unable to transmit message over 8KB, following is the error
2014-02-12 19:36:29,990 - org.sp
You can configure the websocket engine and increase the buffer size.
Watch out, depending on the actual size you'd like to use, remember that those messages will be buffered entirely in memory! You may want to consider using partial messages if your client supports it.
for client side:
@Bean
public static WebSocketStompClient getClient() {
List<Transport> transports = new ArrayList<>();
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
container.setDefaultMaxBinaryMessageBufferSize(1024 * 1024);
container.setDefaultMaxTextMessageBufferSize(1024 * 1024);
transports.add(new WebSocketTransport(new StandardWebSocketClient(container)));
WebSocketClient webSocketClient = new SockJsClient(transports);
WebSocketStompClient stompClient = new WebSocketStompClient(webSocketClient);
stompClient.setInboundMessageSizeLimit(Integer.MAX_VALUE);
stompClient.setMessageConverter(new MappingJackson2MessageConverter());
return stompClient;
}
for server side:
@Bean
public ServletServerContainerFactoryBean createServletServerContainerFactoryBean() {
ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean();
container.setMaxTextMessageBufferSize(32768);
container.setMaxBinaryMessageBufferSize(32768);
logger.info("Websocket factory returned");
return container;
}
Solved it by using clue from http://docs.spring.io/spring/docs/4.0.1.RELEASE/javadoc-api/index.html?org/springframework/web/socket/sockjs/SockJsService.html -got hold of ServletServerContainerFactoryBean and set the properties, this worked
@Bean
public ServletServerContainerFactoryBean createServletServerContainerFactoryBean() {
ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean();
container.setMaxTextMessageBufferSize(32768);
container.setMaxBinaryMessageBufferSize(32768);
logger.info("Websocket factory returned");
return container;
}