长连接 关闭日志打印

This commit is contained in:
2024-11-11 10:45:57 +08:00
parent 4408c0ecc6
commit 5fe605c130
2 changed files with 13 additions and 4 deletions

View File

@@ -38,12 +38,23 @@ public class NotificationConnection {
}
@OnClose
public void onClose() {
public void onClose(CloseReason reason) {
websockets.remove(this); // 将当前的对象从集合中删除
log.info("【连接断开】 用户为:{}", this.session);
log.info("【连接断开】 用户为:{}, 原因为{}", this.session, reason);
// log.info("【连接断开】 总数为:{}", websockets.size());
}
/**
* 错误时调用
* @param session 连接
* @param throwable 异常
*/
@OnError
public void onError(Session session, Throwable throwable) {
log.info("【连接异常】[session({}) 发生异常]", session, throwable);
websockets.remove(this); // 将当前的对象从集合中删除
}
//收到了客户端消息执行的操作
@OnMessage
public void onMessage(String text){

View File

@@ -6,8 +6,6 @@ import org.springframework.web.socket.server.standard.ServerEndpointExporter;
/**
* Configuration of WebSocket
*
* @author db1995
*/
@Configuration
public class WebSocketConfig {