requestRouteToHost android
Asked Answered
K

3

0

Greetings everyone! I'm getting rather fed up with android's ConnectivityManager class. I've been trying for 5 hours to get the requestRouteToHost to work. I'm running my code on the emulator but the requestRouteToHost always fails. I know I have connectivity because I called getActiveNetworkInfo() and it was connected. I've added the ACCESS_NETWORK_STATE and CHANGE_NETWORK_STATE permissions to no avail. Any tips would be greatly appreciated.

EDIT-------- The method InetAddress.isReachable fails as well. I was using the hostname java.sun.com as specified in the docs. I think this is a problem with the emulator. Sam

Karolinekaroly answered 18/3, 2010 at 17:27 Comment(4)
Any chance of putting your code up so we can work out what could be going wrong. SteveRivers
Well, sure. However, there isn't much to see. I mean what part would you like to see?Karolinekaroly
I'm not a noob or anything, I'm actually quite experienced with the android platform. This has just got me confused!Karolinekaroly
conn_man.requestRouteToHost(ConnectivityManager.TYPE_WIFI, lookupHost("localhost")));Karolinekaroly
C
2

Looks like requestRouteToHost() is not implemented for WiFi. WifiStateTracker private class does not have requestRouteToHost() implementation. Instead, default implementation from base class NetworkStateTracker always returns false.

Colchester answered 21/4, 2010 at 6:27 Comment(0)
S
0

I would recommend testing requestRouteToHost() with a real host. Not only am I unconvinced that localhost as a name is necessarily recognized on Android, it's going to be the device/emulator itself, which would go out via neither WiFi nor 3G, so I would expect requestRouteToHost() to fail.

You might also have a problem with wherever you are getting lookupHost() from. For example, I am not sure if this implementation supports localhost.

Snell answered 18/3, 2010 at 18:48 Comment(2)
I've tried a real host. I've tried google.com. Nothing works. Kind suggestion thoughKarolinekaroly
I have also read reports of bug in prior to ICS. #8322981 If you know something please share it with the community?Sha
D
0

The requestRouteToHost(lookupHost()) combination you are doing is very risky

See your code:

conn_man.requestRouteToHost(ConnectivityManager.TYPE_WIFI, lookupHost("localhost")))

Here, you first made a host lookup, and next you are requesting a route to it. It will work fine only for static addresses (like localhost), where no real lookup is done. If you need a DNS lookup to resolve host address, it will fail easily. Generally, requestRouteToHost is handy for static addresses only.

Deandre answered 13/2, 2012 at 12:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.