Sending message to client periodically via Spring Web-Socket

前端 未结 1 685
一个人的身影
一个人的身影 2021-02-04 03:38

I\'m trying to make a connection between client and server via Spring webSocket and I\'m doing this by the help of this link. I want Controller to send a \"hello\" to client eve

1条回答
  •  梦毁少年i
    2021-02-04 04:09

    Please reffer to this portion of the documentation. The way you are trying to send a message is totally wrong. I would modify your above class as follows:

    @EnableScheduling
    @Controller
    public class GreetingController {
    
        @Autowired
        private SimpMessagingTemplate template;
    
        @Scheduled(fixedRate = 5000)
        public void greeting() {
            Thread.sleep(1000); // simulated delay
            System.out.println("scheduled");
            this.template.convertAndSend("/topic/greetings", "Hello");
        }
    
    }
    

    0 讨论(0)
提交回复
热议问题