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

  • kourtneyannmakeup

    kourtneyannm

    19 ŞUBAT 2012
  • The Pet Collective

    The Pet Coll

    5 Ocak 2012
  • WePlayWeWatch

    WePlayWeWatc

    3 Temmuz 2013