mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-08-06 06:25:03 +00:00
fix[net]: 修复没有close socket资源
This commit is contained in:
@@ -114,10 +114,9 @@ public class NetUtils {
|
||||
// 给定的IP未在指定端口范围中
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
InetAddress localHost = InetAddress.getLocalHost();
|
||||
ServerSocket ss = new ServerSocket(port, 50, localHost);
|
||||
ss.close();
|
||||
|
||||
// try-with-resources会自动调用close方法
|
||||
try (ServerSocket ss = new ServerSocket(port)) {
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user