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

  • Erica Griffin

    Erica Griffi

    8 HAZİRAN 2009
  • Glove and Boots

    Glove and Bo

    1 ŞUBAT 2007
  • GoldgenieOfficial

    GoldgenieOff

    23 Temmuz 2009