我用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的经理应用程序时,我无法在监视器上看到任何会话。
我相信,因为它查找的是httpSession而不是websocket会话。

所以有两个问题:

1)有没有办法监视tomcat实例上的这些websocket会话?

2)是否还有类似会话复制(httpSession)的方法用于websocket会话?

谢谢!

最佳答案

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

您可以尝试使用Spring-Session。它可以在其HttpSession集成之上解决会话复制和WebSocket会话。

10-07 19:06
查看更多