监听唤醒端口允许漂移,防止唤醒端口被其他程序占用时无法实现唤醒

This commit is contained in:
chuzhongzai 2025-08-31 14:10:49 +08:00
parent 2caa383f06
commit 0b19a75d7b
2 changed files with 15 additions and 1 deletions

3
.gitignore vendored
View File

@ -35,4 +35,5 @@ build/
.vscode/
### Mac OS ###
.DS_Store
.DS_Store
/.idea/encodings.xml

View File

@ -5,6 +5,8 @@ import cn.hutool.http.HttpResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;
import java.io.IOException;
import java.net.ServerSocket;
import java.util.concurrent.atomic.AtomicInteger;
@ -25,4 +27,15 @@ public class CustomUtil {
}
}
}
public static int _findIdlePort(int port) {
for(int i=port; i<65535; i++){
try(ServerSocket ignored = new ServerSocket(i)){
ignored.close();
return i;
}catch (IOException ignored) {
}
}
return -1;
}
}