nutzmore icon indicating copy to clipboard operation
nutzmore copied to clipboard

websocket 给指定会话发消息

Open Leewell1989 opened this issue 6 years ago • 1 comments

将sessionid存到httpsession的时候不适用固定key,使用httpsessionid作为key不就好了嘛,反正httpsessionid在销毁前是有效的,所以在这个会话内给客户端发消息就很方便了

public void init() {
    super.init(); 
    if (httpSession != null)
        httpSession.setAttribute(httpSession.getId() , session.getId()); 
}
websocketEndpoint.sendJson(httpsession.getAttribute(httpsession.getId()), msg);

Leewell1989 avatar May 19 '18 11:05 Leewell1989

考虑一下一个httpsession对应多个websocket的情况?

原来我一直没提交成功...

wendal avatar Jun 04 '18 03:06 wendal