3

I am trying to communicate to the webservice on my laptop and using and Android phone as the client. I was trying to do a simple login function however, whenever the client tries to communicate with the webservice, this error pops out in the DDMS on Eclipse. I can access the webservice with my home network but not able to do so when i am in my school. In case you might ask this, the IP address in my sch is 172.22.XX.XX. Although i know is a private IP address, but even though my Android phone is connected to the same network, it still can't communicate with the webservice running on my laptop. Can anyone tell me how to solve thie problem

10-20 15:00:42.875: ERROR/AndroidRuntime(6728): fillInStackTrace():java.net.SocketException: No route to host

Here is the function that does the work:

public String[] getPassword(String loginID){

    String[] temp = null;
    SoapObject request = new SoapObject(NAMESPACE, "GetPassword");

    PropertyInfo quotesProperty = new PropertyInfo();
    quotesProperty.setName("LoginID");
    quotesProperty.setValue(loginID);
    quotesProperty.setType(String.class);
    request.addProperty(quotesProperty);

    envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);

    String result = "";
    HttpTransportSE httpRequest = new HttpTransportSE(URL);
    httpRequest.debug = true;

    try
    {
        httpRequest.call(SOAP_ACTION, envelope);
        Log.e("Request",httpRequest.requestDump.toString());

        SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
        Log.e("Response",httpRequest.responseDump.toString());

        result =  response.toString();
        if(result != null){
            temp = result.split(";");
            passwordSecurity crypto = new passwordSecurity();
            temp[0]= crypto.cryptography(temp[0], false); //decrypt the password
        }

    }
    catch(Exception e)
    {
        e.printStackTrace();
        Log.e("AndroidRuntime", "getMessage(): "+e.getMessage());
        Log.e("AndroidRuntime", "getLocalizedMessage(): "+e.getLocalizedMessage());
        Log.e("AndroidRuntime", "fillInStackTrace(): "+e.fillInStackTrace().toString());

    }
    return temp;
}

Warnings from DDMS

10-20 16:56:32.180: WARN/System.err(13034): java.net.SocketException: No route to host
10-20 16:56:32.180: WARN/System.err(13034):     at    org.apache.harmony.luni.platform.OSNetworkSystem.connect(Native Method)
10-20 16:56:32.180: WARN/System.err(13034):     at dalvik.system.BlockGuard$WrappedNetworkSystem.connect(BlockGuard.java:357)
10-20 16:56:32.180: WARN/System.err(13034):     at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:204)
10-20 16:56:32.180: WARN/System.err(13034):     at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:437)
10-20 16:56:32.180: WARN/System.err(13034):     at java.net.Socket.connect(Socket.java:1002)
10-20 16:56:32.180: WARN/System.err(13034):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:75)
10-20 16:56:32.180: WARN/System.err(13034):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:48)
10-20 16:56:32.180: WARN/System.err(13034):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:322)
10-20 16:56:32.180: WARN/System.err(13034):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89)
10-20 16:56:32.180: WARN/System.err(13034):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection(HttpURLConnectionImpl.java:285)
10-20 16:56:32.180: WARN/System.err(13034):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:267)
10-20 16:56:32.180: WARN/System.err(13034):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:205)
10-20 16:56:32.180: WARN/System.err(13034):     at org.ksoap2.transport.ServiceConnectionSE.connect(ServiceConnectionSE.java:76)
10-20 16:56:32.180: WARN/System.err(13034):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:146)
10-20 16:56:32.180: WARN/System.err(13034):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:95)
10-20 16:56:32.180: WARN/System.err(13034):     at android.wps.server.operations.WifiPositioningServices.getPassword(WifiPositioningServices.java:43)
10-20 16:56:32.180: WARN/System.err(13034):     at android.wps.MainActivity$1.onClick(MainActivity.java:67)
10-20 16:56:32.180: WARN/System.err(13034):     at android.view.View.performClick(View.java:2538)
10-20 16:56:32.180: WARN/System.err(13034):     at android.view.View$PerformClick.run(View.java:9152)
10-20 16:56:32.180: WARN/System.err(13034):     at android.os.Handler.handleCallback(Handler.java:587)
10-20 16:56:32.180: WARN/System.err(13034):     at android.os.Handler.dispatchMessage(Handler.java:92)
10-20 16:56:32.180: WARN/System.err(13034):     at android.os.Looper.loop(Looper.java:123)
10-20 16:56:32.180: WARN/System.err(13034):     at android.app.ActivityThread.main(ActivityThread.java:3691)
10-20 16:56:32.180: WARN/System.err(13034):     at java.lang.reflect.Method.invokeNative(Native Method)
10-20 16:56:32.180: WARN/System.err(13034):     at java.lang.reflect.Method.invoke(Method.java:507)
10-20 16:56:32.180: WARN/System.err(13034):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
10-20 16:56:32.180: WARN/System.err(13034):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
10-20 16:56:32.180: WARN/System.err(13034):     at dalvik.system.NativeStart.main(Native Method)
user918197
  • 1,129
  • 6
  • 17
  • 29

4 Answers4

0

I was having issues connecting to my (ASP.NET) web service from another PC due to an authentication issue. After the authentication issue was resolved I was still getting the "No Route to Host" error from my Android App. Turning the WiFi on my device off and back on solved this problem for me.

RiaanDP
  • 1,212
  • 12
  • 18
0

In my case, My code looked like this in my webservice:

public static Song GetSong()
{
  Song song = null;
  // Some database operations
  // Then initialized the object with some data
  if(someValueReturnedFromDb)
  {
    song = new Song();
    song.Source = "Path"; // etc
  }
  return song;
}

After that I simply changed the code to:

public static Song GetSong()
{
  Song song = new Song();
  // Some database operations
  // Then initialized the object with some data
  if(someValueReturnedFromDb)
  {
    song.Source = "Path"; // etc
  }
  return song;
}
Jamshaid K.
  • 3,555
  • 1
  • 27
  • 42
0

From inside the Android emulator, the host computer (your laptop) is 10.0.2.2 -- this should always work, no matter what actual IP addresses the host computer has.

Philipp Reichart
  • 20,771
  • 6
  • 58
  • 65
  • yes.. if i tried running on the emulator, it works. But now when i tried running the program on my Android phone and communicating to my laptop via the wireless network, it won't work and this error was encountered. – user918197 Oct 20 '11 at 08:49
  • You'll either have to change the IP address manually before you deploy to your emulator/device or add [a check to do this automatically](http://stackoverflow.com/questions/2799097/how-can-i-detect-when-an-android-application-is-running-in-the-emulator) – Philipp Reichart Oct 20 '11 at 08:56
  • well... i have always change the IP address each time before running the program where the variable, URL is a string variable as such, "http://172.22.XX.XX:8080". Only the IP address is change when i run my program at home. – user918197 Oct 20 '11 at 09:05
  • Oh, I just re-read your question. Maybe your school blocks traffic on port 8080 -- can you access a web app running on your laptop on port 8080 from your phone while on the school network? – Philipp Reichart Oct 20 '11 at 09:16
  • if the emulator able to run as per normal in my sch does it mean the port is not block? – user918197 Oct 20 '11 at 14:18
  • Try connecting from your phone to your laptop, the emulator might not be affected by any filtering because it runs on the same hardware as your laptop. – Philipp Reichart Oct 20 '11 at 15:15
  • after looking at your previous comment, the program is not an web app but an Android apps. I wished that the port is not block but is there possibility that there might be other problem that caused this error? – user918197 Oct 20 '11 at 15:24
  • Yes, I realize it's a native Android app, not a web app. Any filtering solution wouldn't care (or be able to tell the difference), though, so I just want you to check if you can reach port 8080 on your laptop from your phone when both are in the school network. If you can, the problem is in your code -- if you can't, the network is most likely filtered and you need to use a different port, e.g. 80 on your laptop. Even that might not be enough when the filtering disallows "regular" computers to host any services -- in that case, I'm out of ideas. – Philipp Reichart Oct 20 '11 at 16:40
  • thanks for the comments and ideas. I will definitely try that when i get to sch tml... – user918197 Oct 20 '11 at 17:00
  • see also [here](http://stackoverflow.com/questions/18558047/no-route-to-host-on-device-on-getoutputstream-connected-wirelessly) – Mr_and_Mrs_D Sep 16 '13 at 09:43
0

i am facing the same issue here, with a tablet (motorola xoom 3.2) device.

tablet is 192.168.1.2 pc 192.162.1.3

when i set the url to 192.162.1.3 i get this stack trace

12-10 22:18:22.050: WARN/System.err(6274): java.net.SocketException: No route to host
12-10 22:18:22.050: WARN/System.err(6274): at     org.apache.harmony.luni.platform.OSNetworkSystem.connect(Native Method)
12-10 22:18:22.050: WARN/System.err(6274): at dalvik.system.****BlockGuard$WrappedNetworkSystem.connect(BlockGuard.java:369)****

when i try a non existing ip, i still get no route to host but not this blockguard inside the stack trace. Loopback or browser works fine as well.

https://groups.google.com/group/android-developers/browse_thread/thread/7d96e7297da43cec

i guess its the same issue but don't have any clue

vodoo solution: after rebooting the tablet and having the same issue, what i did was disable usb-debugging on device, disconnect wlan (flight mode), re-connect, restart usb debugging and for some reason this seems to solve the issue

lorthos
  • 437
  • 3
  • 9