Java Network Programming from entry to mastery (12): Use the isReachable method to test whether the host can be connected

Source: Internet
Author: User

In J2SE5.0InInetAddressAddedIsReachableMethod. You can use this method to test whether the host can be connected. This method has two overload forms, which are defined as follows: Public BooleanIsReachable (IntTimeout)ThrowsIOException
Public BooleanIsReachable (NetworkInterface netif,IntTtl,IntTimeout)ThrowsIOException

The first overload form hasTimeoutParameter. You can use this parameter to set connection timeout (unit: milliseconds ). The second overload mode has two more parameters:NetifAndTtl. PassNetifYou can useNetworkInterfaceObject To determine which network interface the client uses to test the connectivity of the host.TtlIt refers to the maximum number of connection hops during the connectivity test (the maximum number of routes from the client to the remote host is the maximum number of connection hops. A route is called a hop inWindowsIn the network connectionTCP/IPIn the "Settings" dialog box, you can set the interface hops at the bottom. If the maximum number of connection hops is reached, the remote host is not found,IsReachableThe method assumes that the client and the remote host are not connected.

IsReachableThe method is to connect to the hostEchoPort to determine whether the client and the server can be connected. HoweverInternetThis method may fail to connect to the remote host due to factors such as the fire wall (in fact, the remote host can be connected). Therefore,IsReachableInInternetIs not reliable. But we canIsReachableThe method is applied to the LAN.

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.