Skip to content

Commit

Permalink
feat(Communication): 使用try-with-resources自动关闭Socket
Browse files Browse the repository at this point in the history
  • Loading branch information
shulng committed Sep 7, 2024
1 parent 980825c commit bfc4239
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/main/java/cc/baka9/catseedlogin/bukkit/Communication.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,15 @@ private static void handleConnectRequest(Socket socket, String playerName) {
CatScheduler.runTask(() -> {
boolean result = LoginPlayerHelper.isLogin(playerName);
CatSeedLogin.instance.runTaskAsync(() -> {
try {
socket.getOutputStream().write(result ? 1 : 0);
socket.getOutputStream().flush(); // 确保数据发送
try (Socket autoCloseSocket = socket) {
autoCloseSocket.getOutputStream().write(result ? 1 : 0);
autoCloseSocket.getOutputStream().flush(); // 确保数据发送
} catch (IOException e) {
CatSeedLogin.instance.getLogger().warning("发送连接结果时发生错误: " + e.getMessage());
} finally {
try {
socket.close();
} catch (IOException e) {
CatSeedLogin.instance.getLogger().warning("关闭Socket时发生错误: " + e.getMessage());
}
}
});
});
}


}

0 comments on commit bfc4239

Please sign in to comment.