Skip to content

Commit

Permalink
Reuse port
Browse files Browse the repository at this point in the history
  • Loading branch information
RetGal committed Feb 12, 2025
1 parent 922e333 commit d69db44
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,11 @@ private int detectEnvironment() {
publicIp = resolvePublicIp();
}
String remoteHost = configuration.getServerName();
if (!selfTest(publicIp, configuration.getServerPort(), remoteHost)) {
// reuse the port number if possible
int portNumber = token.getLocalPort() != 0 ? token.getLocalPort() : configuration.getServerPort();
if (!selfTest(publicIp, portNumber, remoteHost)) {
// try a random port number if we couldn't open the one of the server
int portNumber = new Random().nextInt(8975) + 1025;
portNumber = new Random().nextInt(8975) + 1025;
if (selfTest(publicIp, portNumber, remoteHost)) {
return portNumber;
}
Expand Down

0 comments on commit d69db44

Please sign in to comment.