Websocket java client Spring + Stomp: Transport error: ConnectionLostException


I'm trying to create an standalone Java app as a websocket client using for this Spring with Stomp and Sockjs, taking in consideration the spring specifications and the spring-portafolio examples and I'm getting this error:

15:18:01.342 [main] DEBUG com.example.client.WebSocketClientTest - Connecting to : ws://localhost:8080/socket/hello 15:18:01.541 [WebSocketClient-AsyncIO-1] ERROR com.example.client.MyStompSessionHandler - Transport error org.springframework.messaging.simp.stomp.ConnectionLostException: Connection closed at org.springframework.messaging.simp.stomp.DefaultStompSession.afterConnectionClosed(DefaultStompSession.java:483) [spring-messaging-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.web.socket.messaging.WebSocketStompClient$WebSocketTcpConnectionHandlerAdapter.afterConnectionClosed(WebSocketStompClient.java:354) [spring-websocket-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.web.socket.sockjs.client.AbstractClientSockJsSession.afterTransportClosed(AbstractClientSockJsSession.java:321) [spring-websocket-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.web.socket.sockjs.client.WebSocketTransport$ClientSockJsWebSocketHandler.afterConnectionClosed(WebSocketTransport.java:172) [spring-websocket-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter.onClose(StandardWebSocketHandlerAdapter.java:141) [spring-websocket-4.3.2.RELEASE.jar:4.3.2.RELEASE]...

My code in the java client side is:

StandardWebSocketClient webSocketClient = new StandardWebSocketClient(); List<Transport> transports = new ArrayList<>(); transports.add(new WebSocketTransport(webSocketClient)); SockJsClient sockJsClient = new SockJsClient(transports); ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); taskScheduler.afterPropertiesSet(); String stompUrl = "ws://localhost:8080/socket/hello"; WebSocketStompClient stompClient = new WebSocketStompClient(sockJsClient); stompClient.setMessageConverter(new StringMessageConverter()); stompClient.setTaskScheduler(taskScheduler); stompClient.setDefaultHeartbeat(new long[] {0, 0}); StompSessionHandler sessionHandler = new MyStompSessionHandler(); stompClient.connect(stompUrl, sessionHandler); stompClient.setTaskScheduler(taskScheduler);

And the server side was made using Spring MVC with Stomp and SockJs, the server works perfectly with a javascript client, this is the config that I used:

public void configureMessageBroker(MessageBrokerRegistry config) { config.enableSimpleBroker("/topic"); config.setApplicationDestinationPrefixes("/app"); } public void registerStompEndpoints(StompEndpointRegistry registry) { registry.addEndpoint("/hello") .setHandshakeHandler(new DefaultHandshakeHandler(new TomcatRequestUpgradeStrategy())) .withSockJS(); }

What am I doing wrong? Can anyone give me an idea of how to fix it or how to create a Java client to connect with an spring websocket server?

Thanks in advance..


I had the same problem. Cause was recieving too big message which default STOMP Spring/Tomcat WS client cannot handle because <em>it is not capable of partial messaging</em>. <a href="https://stackoverflow.com/a/36457020/5148407" rel="nofollow">This StackOverflow answer</a> worked for me (I have set MAX_TEXT_MESSAGE_BUFFER_SIZE=20*1024*1024):

WebSocketContainer container = ContainerProvider.getWebSocketContainer(); container.setDefaultMaxTextMessageBufferSize(MAX_TEXT_MESSAGE_BUFFER_SIZE); WebSocketClient wsClient = new StandardWebSocketClient(container);

Setting inboundMessageSizeLimit had no effect:

WebSocketStompClient stompClient = new WebSocketStompClient(sockJsClient); stompClient.setInboundMessageSizeLimit(Integer.MAX_VALUE);


  • Java Class for retrieving Large String from Oracle_db of LOB dataType
  • PySpark sqlContext read Postgres 9.6 NullPointerException
  • spark importing data from oracle - java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
  • Gradle Build Failed For Task app:processReleaseResources
  • Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.goog
  • How to add source files of library jars?
  • “export as runnable JAR” option is missing
  • Creating grails binary plugin results in jar file wich contains all groovy files with comments
  • Convert gwt project into maven gwt project
  • java.lang.NoClassDefFoundError for org/springframework/aop/framework/AbstractAdvisingBeanPostProcess
  • VLCJ - playing a video from the “res” folder works great in eclipse, but not from the executable JAR
  • Difficulties with updating my Mac to the latest Java JDK
  • Export Applet Java with referenced libraries
  • What is an Artifact?
  • Spring roo - how to install spring surf
  • JENKINS: ERROR when I try to use an older JDK for a specific maven project
  • Referencing external dependencies in GGTS by convention
  • maven-shade-plugin reports: Error creating shaded jar: …target/classes (Is a directory)
  • YAJSW window service did not start
  • still not find package, after 'mvn install'
  • Maven repository location is not updated in eclipse
  • JConsole Main class
  • How to resolve dependencies from one gradle project to another gradle project in my Eclipse workspac
  • integrate POCO library in android ndk
  • Creating a setup.exe in InstallShield in Visual Studio
  • Cannot find “Grammar.txt” in python-sphinx
  • C# Excel interop - how to test if interop object is still working and performing a task?
  • “mvn clean generate-source” could not resolve dependencies
  • In Java, how can I construct a File from a resource?
  • Why does java tzupdater add leap seconds?
  • Android Studio Can't Find tools.jar
  • HTTP/2 streams vs HTTP/1.1 connections
  • PHP buffered output depending on server setting?
  • MVC3 Razor - ListBox pre-select not working
  • Reading JSON from a file using C++ REST SDK (Casablanca)
  • FB SDK and cURL: Unknown SSL protocol error in connection to graph.facebook.com:443
  • Trying to switch camera back to front but getting exception
  • Is there a mandatory requirement to switch app.yaml?
  • -fvisibility=hidden not passed by compiler for Debug builds
  • UserPrincipal.Current returns apppool on IIS