Java network programming from getting started to mastering (12): Using the Isreachable method to detect if a host can be connected

Source: Internet
Author: User

a isreachable method has been added to the InetAddress class in j2se5.0. You can use this method to detect if the host is connected . This method has two overloaded forms, which are defined as follows:

public boolean isreachable (int-Timeout) throws IOException public boolean isreachable (NetworkInterface netif, int ttl, int Timeout) throws IOException

The first overloaded form has a timeout parameter, which allows you to set the connection timeout (in milliseconds). The second overloaded form has more than two parameters: Netif and TTL. The Netif parameter allows you to use a NetworkInterface object to determine which network interface the client uses to test the connectivity of the host. TTL refers to the maximum number of connection hops in the test connectivity process (the maximum routing count from the client to the remote host is the maximum connection metric, a route is called a hop, and the interface metric can be set at the bottom of the Advanced TCP/IP Settings dialog box in a Windows network connection). If the maximum connection metric is reached and the remote host is not found, the Isreachable method considers that the client and the remote host are not connected.

The Isreachable method is to determine whether the client and server are connected by connecting to the Echo port of the host. However, using this method on the Internet may not be able to connect to remote hosts (in fact, remote hosts can be connected) because of factors such as arson, so isreachable is not reliable on the internet. But we can apply the Isreachable method to the local area network .

Java network programming from getting started to mastering (12): Using the Isreachable method to detect if a host can be connected

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.