gpt4 book ai didi

session - Tomcat 8 - websockets session 和复制

转载 作者:行者123 更新时间:2023-11-28 22:30:40 24 4
gpt4 key购买 nike

我用 tomcat 8 websockets 创建了一个简单的项目。这是一个片段:

public void onMessage(String message, Session session) 
throws IOException, InterruptedException {

// Print the client message for testing purposes
System.out.println("Received: " + message);

// Send the first message to the client
session.getBasicRemote().sendText("This is the first server message");

如您所见,websocket 使用对象 Session (javax.websocket.session)我的问题是,当我进入 tomcat 的管理器应用程序时,我在监视器上看不到任何 session 。我相信,因为它寻找的是 httpSession 而不是 websocket session 。

所以 2 个问题:

1) 有没有办法在 tomcat 实例上监控这些 websocket session ?

2) 对于 websocket session 是否也有像 session replication (httpSession) 这样的方法?

谢谢!

最佳答案

有趣的是,似乎有一种方法可以根据 WebSocket 事件更新 HttpSession。看这个Discussion about WebSocket SPEC 175

您可以尝试使用 Spring-Session .它可以在其 HttpSession 集成之上处理 session 复制和 WebSocket session 。

关于session - Tomcat 8 - websockets session 和复制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20177040/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com