我按照这里的示例设置了websocket服务器。 https://www.eclipse.org/jetty/documentation/current/jetty-websocket-server-api.html
public class MySocketCreator implements WebSocketCreator {
private MyEchoSocket mySocket;
@Inject
public MyAdvancedEchoCreator(MyEchoSocket mySocket) {
this.mySocket = mySocket;
}
@Override
public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp) {
return mySocket;
}
}
我遇到的问题是:
由于MyEchoSocket看起来像这样:
@WebSocket(maxTextMessageSize = 64 * 1024)
public class MyEchoSocket {
private final CountDownLatch closeLatch;
private Set<Session> session;
public MyEchoSocket() {
sessionList = new ArrayList<>();
}
@OnWebSocketClose
public void onClose(int statusCode, String reason) {
....
}
@OnWebSocketConnect
public void onConnect(Session session) {
sessionList.add(session);
}
@OnWebSocketMessage
public void onMessage(String msg) {
....
}
}
我遇到的问题是,当连接多个不同的客户端,并且一个脱机时,我不知道哪个客户端脱机。 或者我做错了,每个新客户端我得到一个新的实例:MyEchoSocket 我用它来跟踪会话?