SORU
12 Ocak 2009, PAZARTESİ


Yuva: bağlantı noktası kullanılabilirliği Java kullanarak bulmak

Nasıl programlı olarak verilen bir makine Java kullanarak bir bağlantı noktası kullanılabilirliği belirleyebilirim?

ben.e port numarası verilir, zaten kullanılmakta olup olmadığını belirlemek?.

CEVAP
12 Ocak 2009, PAZARTESİ


Bu implementation Apache geliyor camel proje:

/**
 * Checks to see if a specific port is available.
 *
 * @param port the port to check for availability
 */
public static boolean available(int port) {
    if (port < MIN_PORT_NUMBER || port > MAX_PORT_NUMBER) {
        throw new IllegalArgumentException("Invalid start port: "   port);
    }

    ServerSocket ss = null;
    DatagramSocket ds = null;
    try {
        ss = new ServerSocket(port);
        ss.setReuseAddress(true);
        ds = new DatagramSocket(port);
        ds.setReuseAddress(true);
        return true;
    } catch (IOException e) {
    } finally {
        if (ds != null) {
            ds.close();
        }

        if (ss != null) {
            try {
                ss.close();
            } catch (IOException e) {
                /* should not be thrown */
            }
        }
    }

    return false;
}

De DatagramSocket port UDP ve TCP mevcut olup olmadığını kontrol etmek için kontrol ediyorlar.

Bu yardımcı olur umarım.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Jared Busch

    Jared Busch

    25 Mayıs 2011
  • Mismag822 - The Card Trick Teacher

    Mismag822 -

    18 EKİM 2008
  • SomeOne Pro

    SomeOne Pro

    25 EKİM 2013