I have some Ping code like this,
try {
//InetAddress server = Inet4Address.getByName
("www.google.com"); // case 1
InetAddress server = Inet4Address.getByAddress(new
String
("10.0.2.2").getBytes()); // case 2
if (server.isReachable(3000)) {
Log.d("Test", "Pinged!");
} else {
Log.d("Test", "***** Address is not
reachable!");
}
} catch (UnknownHostException e) {
Log.e("Test", "Host Exception: Server Not
Found.");
} catch (IOException e) {
Log.e("Test", "I/O Exception: Server Not
Found.");
}
I also have INTERNET permission set in the manifest. I run this in the
Emulator and always get errors. For case 1, I get:
D/InetAddress( 885): www.google.com: 209.85.225.99 (family 2, proto
6)
D/InetAddress( 885): www.google.com: 209.85.225.104 (family 2, proto
6)
D/InetAddress( 885): www.google.com: 209.85.225.105 (family 2, proto
6)
D/InetAddress( 885): www.google.com: 209.85.225.147 (family 2, proto
6)
D/InetAddress( 885): www.google.com: 209.85.225.106 (family 2, proto
6)
D/InetAddress( 885): www.google.com: 209.85.225.103 (family 2, proto
6)
D/Test ( 885): ***** Address is not reachable!
Case 2:
E/Test ( 914): Host Exception: Server Not Found.
I understand there is some issue with ping in Emulator, but at least
case 2 should work because "10.0.2.2" is just local router. Did I do
something wrong?
Thanks for your help.
--
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