3

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 ?

Oto-obong Eshiett
  • 1,459
  • 3
  • 18
  • 33

1 Answers1

4

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

var socket = new WebSocket('ws://localhost:8080/websocket-example/websocket');
airush
  • 722
  • 9
  • 19