Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring boot Websocket with stomp js: I keep getting Whoops! Lost connection to http://localhost:8080/ws

I want to integrate chatting into an application I made, and after following some tutorials and running the application I keep getting "Whoops! Lost connection to http://localhost:8080/ws" on my console I tried using sockjs path as"/ws" but still got the same error, please can someone explain to me what i am doing wrong ?

here is the snippet of my code:

 @Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfiguration extends AbstractWebSocketMessageBrokerConfigurer {


    @Override
    public void registerStompEndpoints(StompEndpointRegistry stompEndpointRegistry) {

        stompEndpointRegistry.addEndpoint("/ws")
                .setHandshakeHandler(new CustomHandshakeHandler())
                .withSockJS();

    }

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {

        registry.setApplicationDestinationPrefixes("/app");

        registry.enableSimpleBroker("/message");

    }
}

and this is my client

    var socket = new SockJS('http://localhost:8080/ws');

stompClient = Stomp.over(socket);

stompClient.connect({}, onConnected, onError);

function onConnected() {

    console.log("its working");

}


function onError(error) {

    console.log(error);
}
like image 913
appzone_oto Avatar asked May 04 '18 08:05

appzone_oto


People also ask

Does Spring boot support WebSocket?

Spring Boot includes the spring-WebSocket module, which is compatible with the Java WebSocket API standard (JSR-356). Implementing the WebSocket server-side with Spring Boot is not a very complex task and includes only a couple of steps, which we will walk through one by one.

Is STOMP deprecated?

This project is no longer maintained. If you encounter bugs with it or need enhancements, you can fork it and modify it as the project is under the Apache License 2.0.

What is STOMP in WebSockets?

STOMP, an acronym for Simple Text Oriented Messaging Protocol, is a simple HTTP-like protocol for interacting with any STOMP message broker. Any STOMP client can interact with the message broker and be interoperable among languages and platforms.


1 Answers

i am not sure about the CustomHandshakeHandler which you are using here. so that might be an issue to look into. also, consider to add .setAllowedOrigins("*") to your stompEndpointRegistry.

apart from that, the code looks ok and should work IMO.

like image 128
Joachim Avatar answered Oct 24 '22 21:10

Joachim