Android : How can I troubleshoot connection failures from the emulator?

on Thursday, March 26, 2015


I am trying to connect with the emulator with a server having a hostname set.

The actual IP is an internal IP and I am connected via WIFI to the network. I can access the IP from the browser just fine but with the Emulator I either get:



java.net.UnknownHostException: Unable to resolve host “internal.server.com”: No address associated with hostname at java.net.InetAddress.lookupHostByName(InetAddress.java:427)



And a couple of times I got a Connection refused for some reason.



Caused by: android.system.ErrnoException: connect failed: ECONNREFUSED (Connection refused)



I have tried adding a proxy in the Emulator settings in case it was a routing issue, removing the proxy but it is not possible to connect.

How can I debug this?


The way I try to connect is:



HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
HttpResponse response = null;
response = client.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
etc


In my manifest I have:



<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>


How can I troubleshoot connection failures from the emulator?


0 comments:

Post a Comment