How to call @SendTo from Normal Request Call i.e @RequestMapping

后端 未结 1 1460
忘了有多久
忘了有多久 2021-02-04 10:57

I have implemented Web Socket using Spring MVC and it is working fine for me i.e work from one browser to another browser which is open for those socket using this code.

相关标签:
1条回答
  • 2021-02-04 11:29

    I have found solution for that

    @Autowired
    private SimpMessagingTemplate template;
    
    
    @RequestMapping(value = "/sendMessage")
    public void sendMessage() throws Exception {
        this.template.convertAndSend("/topic/greetings", new HelloMessage(
                (int) Math.random(), "This is Send From Server"));
    }
    

    by using this we can send message to open WebSocket.

    Thanks

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