Created
February 2, 2015 03:57
-
-
Save ingramchen/adacc38c22f6506c0053 to your computer and use it in GitHub Desktop.
Java scan available port
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// good for unit test | |
public static int scanAvailablePort() throws IOException { | |
try (ServerSocket serverSocket = new ServerSocket(0)) { | |
return serverSocket.getLocalPort(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment