0

I am using websocket.

I want to send "message" to server.

ex) at Client

function do_sync() {

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

}

but i don't know how to get "message" at Controller.

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

String message = ex) message from client.

}

how get message at Controller?

4

1 回答 1

1

Actually you need nothing special: the websocket message payload can be simply mapped to the method param:

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

Please, read more in Docs: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html#websocket-stomp-handle-annotations

于 2014-08-03T14:02:51.250 回答