返回可用的随机端口

This commit is contained in:
xlongwei 2019-09-03 21:49:31 +08:00
parent b9eaf280cd
commit 14c308fde6

View File

@ -160,8 +160,9 @@ public class NetUtil {
*/ */
public static int getUsableLocalPort(int minPort, int maxPort) { public static int getUsableLocalPort(int minPort, int maxPort) {
for (int i = minPort; i <= maxPort; i++) { for (int i = minPort; i <= maxPort; i++) {
if (isUsableLocalPort(RandomUtil.randomInt(minPort, maxPort + 1))) { int randomPort = RandomUtil.randomInt(minPort, maxPort + 1);
return i; if (isUsableLocalPort(randomPort)) {
return randomPort;
} }
} }