Skip to content

Instantly share code, notes, and snippets.

@LaxWasHere
Created October 12, 2014 20:50
Show Gist options
  • Save LaxWasHere/27360f8b999ae112695d to your computer and use it in GitHub Desktop.
Save LaxWasHere/27360f8b999ae112695d to your computer and use it in GitHub Desktop.
Checks if a port is being used or not.
public boolean checkPortAvailablity(int port) {
ServerSocket socket = null;
try {
socket = new ServerSocket(port);
return true; // The port is available
} catch (IOException e) {
return false; //The port is being used.
} finally {
if (socket != null) {
try {
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment