Spring WebSocket @SendToSession: send message to specific session

前端 未结 3 774
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-28 02:49

Is it possible to send a message to specific session?

I have an unauthenticated websocket between clients and a Spring servlet. I need to send an unsolicited message

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-28 03:08

    You need to simply add the session id in

    • Server Side

      convertAndSendToUser(sessionId,apiName,responseObject);

    • Client Side

      $stomp.subscribe('/user/+sessionId+'/apiName',handler);

    Note:
    Dont forget to add '/user' in your end point in server side.

提交回复
热议问题