Skip to content

Instantly share code, notes, and snippets.

@paganotoni
Created December 2, 2012 16:09
Show Gist options
  • Save paganotoni/4189504 to your computer and use it in GitHub Desktop.
Save paganotoni/4189504 to your computer and use it in GitHub Desktop.
Checking port in use
boolean portTaken = false;
ServerSocket socket = null;
try {
socket = new ServerSocket(portNumber);
} catch (IOException e) {
portTaken = true;
} finally {
// Clean up
if (socket != null) socket.close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment