Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i make my springboot app websocket app get connected via a "ws://" url while using stomp

I have a springboot app and i want to make the websocket connect via devices like phone so i am looking for a way to make my websocket have an entry point that starts with "ws://". When testing my default websocket url which is supposed to be "ws://localhost:8080/websocket-example" on "http://www.websocket.org/echo.html" it does not go through. but the sockjs calls it in my client side using ("http://localhost:8080/websocket-example") which works :

    var socket = new SockJS('http://localhost:8080/websocket-example');

    stompClient = Stomp.over(socket);

    stompClient.connect({},function (frame) {


}

I am presently using stomp on it and my configuration looks like this:

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfiguration extends AbstractWebSocketMessageBrokerConfigurer {


    @Override
    public void registerStompEndpoints(StompEndpointRegistry stompEndpointRegistry) {
        stompEndpointRegistry.addEndpoint("/websocket-example")
                .setHandshakeHandler(new CustomHandshakeHandler()).setAllowedOrigins("*")
                .withSockJS();
    }

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        registry.enableSimpleBroker("/topic");
        registry.setApplicationDestinationPrefixes("/app");
    }
}

according to this post it said i could achieve a ws:// entrypoint by removing .withSockJS() which i did, but it still didnt work (on further reading, it was stated that this doesnt work on springboot). The other option was to remove stomp totally, this option works, but then i wouldn't be able to route messages directly to individuals users.

How can i create a ws:// entry point while maintaining stomp on my server side ?

like image 244
Oto-obong Eshiett Avatar asked Sep 15 '25 03:09

Oto-obong Eshiett


1 Answers

I had a similar problem. Try this, should help.

var socket = new WebSocket('ws://localhost:8080/websocket-example/websocket');
like image 197
airush Avatar answered Sep 17 '25 18:09

airush