Spring WebSocket does not send data back to client subscriber

I am trying to get response from server to browser using spring websockets. Periodically server sends messages to the client.

My problem is, I have two pages. One is directly under the webapps and it's a jsp page, and other is under webapps->pages->html, it is a html page. The page which is direclty under the webapps folder can receive the server response.Here is how I connect. Both pages have same code.

    var url='/WBS/secure/simplemessages';
            var socket = new SockJS(url);
            stompClient = Stomp.over(socket);
            stompClient.connect('user', 'guest', function(frame) {
                stompClient.subscribe("/topic/simplemessagesresponse", function(servermessage) {//Callback when server responds
                alert('sm: '+servermessage);
                    showServerBroadcast((servermessage.body).messageContent, false);

Response comes back as `Web Socket Opened... stomp.js:134

CONNECT login:user passcode:guest accept-version:1.1,1.0 heart-beat:10000,10000`

According to the prefix, my web.xml has also been changed. I use Spring 4.1.0 and here is web.xml



Here is my websocketconfigure class..

public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

      private SimpMessagingTemplate template;

      private TaskScheduler scheduler = new ConcurrentTaskScheduler();
    public void registerStompEndpoints(StompEndpointRegistry registry) {

    public void configureMessageBroker(MessageBrokerRegistry config) {

        config.enableSimpleBroker("/topic/", "/queue/");

    private void broadcastTimePeriodically() {

      scheduler.scheduleAtFixedRate(new Runnable() {
         public void run() {
             template.convertAndSend("/topic/simplemessagesresponse", "server sending back -response"+new Date());

      }, 4000);


    public void configureClientInboundChannel(ChannelRegistration registration) {

   public void configureClientOutboundChannel(ChannelRegistration registration) {
    public boolean configureMessageConverters(List<MessageConverter> arg0) {
        return true;
    public void configureWebSocketTransport(WebSocketTransportRegistration arg0) {

in the method, broadcastTimePeriodically() periodically I send a message. I checked the schedular working and found it works well.

Any one let me know why one page cannot have the response from server which is sent periodically.



Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.