Code example for ServerSocket

Methods: close, setReuseAddress

0
    private boolean isPortAvailable(int port) {
 
        ServerSocket ss = null;
 
        try { 
            ss = new ServerSocket(port);
            ss.setReuseAddress(true);
            return true; 
 
        } catch (IOException e) {
        } finally { 
 
            if (ss != null) {
                try { 
                    ss.close();
                } catch (IOException e) {
                    /* should not be thrown */ 
                } 
            } 
        }