1
zj
2024-08-22 87ae8174c670dad02f4da2ab66df32dd573a03a8
websocketSerivce/src/main/java/org/example/websocket/server/WsServer.java
@@ -90,8 +90,7 @@
    @OnError
    public void onError(Session session, @NonNull Throwable throwable) {
        threadLocalData.remove(session.getId());
        wsServers.remove(this);
        onClose();
        log.error("连接发生报错: {}", throwable.getMessage());
        throwable.printStackTrace();
    }
@@ -349,13 +348,9 @@
    // 关闭会话的方法
    private void closeSession(Session session, String reason) {
        try {
            threadLocalData.remove(session.getId());
            session.close(new CloseReason(CloseReason.CloseCodes.UNEXPECTED_CONDITION, reason));
        } catch (IOException e) {
            log.error("强制断开连接----异常: {}", e.getMessage());
        }
        threadLocalData.remove(session.getId());
        wsServers.remove(this);
        log.info(reason);
        onClose();
    }
}