答案 0 :(得分:0)
在没有看到您的代码的情况下,很难说出具体的内容,但通常您只需将列放入列表@Component
public class YourHandler extends TextWebSocketHandler {
private final static Logger logger = LoggerFactory.getLogger(YourHandler .class);
private List<WebSocketSession> sessions = new CopyOnWriteArrayList<>();
@Override
public void afterConnectionEstablished(WebSocketSession session) {
logger.debug("Connected : " + session);
sessions.add(session);
}
@Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) {
try {
//check the close status if you want...
if (!status.equals(CloseStatus.NORMAL)) {
session.close();
}
} catch (IOException e) {
logger.error("Cannot close session on afterConnectionClosed ", e);
}
sessions.remove(session);
}
@Override
public void handleTransportError(WebSocketSession session, Throwable exception) {
logger.debug("error has occured with the following session {}", session);
try {
session.close();
} catch (IOException e) {
logger.error("Cannot close session on handleTransportError ", e);
}
}
@Override
protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
logger.debug("Receive : " + message.getPayload());
}
}
并取l
,然后手动填写缺失值。