监听唤醒端口允许漂移,防止唤醒端口被其他程序占用时无法实现唤醒
This commit is contained in:
+2
-1
@@ -35,4 +35,5 @@ build/
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
||||
.DS_Store
|
||||
/.idea/encodings.xml
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user