保存 WebSocketSession 并通知该会话,

问题描述

我正在保存 webSocketSession,并在一种方法中检索该会话并向该会话发送消息,但在我的 websocket 客户端的 .html 文件中没有看到该消息,

@Override
public Mono<Void> handle(WebSocketSession webSocketSession) {
  
   sessions.put(webSocketSession.getId(),webSocketSession)
   return webSocketSession.send(Flux.interval(Duration.ofSeconds(20)).map(i -> 
      webSocketSession.textMessage("MessageSentDirectly")));
 }

public Mono<Void> sendNotification(String sessionId,String notificationMessage) {
    WebSocketSession session = sessions.get(sessionId);
   
    return session.send(Flux.interval(Duration.ofSeconds(1)).map(i -> 
     session.textMessage("MessageAfterRetreiveSession"))
    
 }

我有一个用于 WebsocketClient 的 .html 和 .js 文件,在该 html 文件中我可以看到 MessageSentDirectly 但我没有看到 MessageAfterRetreiveSession 字符串,

为什么我在调用 sendNotification 方法时没有在客户端收到 MessageAfterRetreiveSession?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)