【问题标题】:How to get message using websocket?如何使用 websocket 获取消息?
【发布时间】:2014-08-03 13:32:29
【问题描述】:

我正在使用 websocket。

我想向服务器发送“消息”。

ex) 在客户处

function do_sync() {

    stompClient.send("/action/test", {}, "message");

}

但我不知道如何在 Controller 获取“消息”。

@MessageMapping("/test")
public void sync() throws Exception {

String message = ex) message from client.

}

如何在 Controller 获取消息?

【问题讨论】:

    标签: java websocket spring-websocket


    【解决方案1】:

    其实你不需要什么特别的:websocket消息payload可以简单地映射到方法参数:

    @MessageMapping("/test")
    public void sync(String payload) throws Exception {
      ....
    }
    

    请在文档中阅读更多内容:http://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html#websocket-stomp-handle-annotations

    【讨论】:

      猜你喜欢
      • 2020-11-27
      • 1970-01-01
      • 2021-07-31
      • 1970-01-01
      • 1970-01-01
      • 2011-04-16
      • 2020-03-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多