Created
October 12, 2014 20:50
-
-
Save LaxWasHere/27360f8b999ae112695d to your computer and use it in GitHub Desktop.
Checks if a port is being used or not.
This file contains 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
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