mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-08-09 16:25:41 +00:00
Update NetUtils.java
无法检测本地端口时候被占用 创建 ServerSocket 时 指定本地ip 端口被占用 异常为 java.net.BindException: Address already in use (Bind failed)
This commit is contained in:
@@ -114,9 +114,12 @@ public class NetUtils {
|
||||
// 给定的IP未在指定端口范围中
|
||||
return false;
|
||||
}
|
||||
try (ServerSocket ss = new ServerSocket(port)) {
|
||||
try {
|
||||
InetAddress localHost = InetAddress.getLocalHost();
|
||||
ServerSocket ss = new ServerSocket(port, 50, localHost);
|
||||
ss.close();
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user