On Mon, Dec 27, 2010 at 12:46 PM, bc <[email protected]> wrote:
> I am stumped. InetAdress.isReachable simply does not work. By that I
> mean, it always returns false for an external host.
>
> I have tried searching the internet to see if anybody else is having
> the same problem, I have found a few people have had the same problem,
> but cannot really find an explanation why.
>
> I have tried this on multiple devices with the same result.
>
> boolean blnResult =
> InetAddress.getByName("localhost").isReachable(20000);
>
> The above line of code works every time. If I change the "localhost"
> to an external host that I can verify "isReachable", the result is
> always false.
>
> blnResult =
> InetAddress.getByName("www.google.com").isReachable(20000);
> blnResult = InetAddress.getByName("4.2.2.2").isReachable(20000);
>
> The above lines always return false, even though I can use a terminal
> emulator on the same device and get a true result.
>
> Can somebody more experienced with Android or perhaps a Google
> engineer please give a plausible explanation for this.

http://stackoverflow.com/questions/2935325/android-debugging-inetaddress-isreachable

isReachable() attempts to connect to port 7, which may be eaten by
firewalls. This is a legacy holdover from Java -- I would recommend
trying to do something more meaningful, like an HTTP GET request on a
known good URL if you are trying to see if a Web service is reachable.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

Warescription: Three Android Books, Plus Updates, One Low Price!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to