@OnMessage
public void onPong(PongMessage pongMessage,Session session) {
log.info("接收pong消息"+userId);
ByteBuffer byteBuffer = pongMessage.getApplicationData();
this.state=1;
}
@Scheduled(cron = "0 0/2 * * * ? ")
public void heartbeat() throws IOException {
for (WebSocketServer item : webSocketSet) {
try {
if (this.state!=1){
log.error("上轮检测未通过,移除"+userId);
webSocketSet.remove(item);
subOnlineCount();
}else {
item.session.getBasicRemote().sendPing(new PingMessage().getPayload());
item.state = 2;
}
} catch (IOException e) {
log.error("错误,移除websocket UserId:"+item.userId);
webSocketSet.remove(item);
subOnlineCount();
}
}
}