Java HTTP Port Find available(int port)

Here you can find the source of available(int port)

Description

available

License

Open Source License

Declaration

static boolean available(int port) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;

import java.net.Socket;

public class Main {
    static boolean available(int port) {
        Socket s = null;//from  w  ww.  j a  v a2s .  c  o m
        try {
            s = new Socket("localhost", port);

            // If the code makes it this far without an exception it means
            // something is using the port and has responded.
            return false;
        } catch (IOException e) {
            return true;
        } finally {
            if (s != null) {
                try {
                    s.close();
                } catch (IOException e) {
                    throw new RuntimeException("You should handle this error.", e);
                }
            }
        }
    }
}

Related

  1. available(final int port)
  2. available(int port)
  3. available(int port)
  4. available(int port)
  5. available_port()
  6. availableAndReturn(int MIN_PORT_NUMBER, int MAX_PORT_NUMBER)
  7. availablePort()