title: Android App connecting to REST Service - Connection Refused
body: <p>I am developing an Android app that involves calls to a RESTful API. I have the REST service written in Python, running on my laptop (<code>192.168.156.1</code>) on port 8080. I have my phone tethered to my laptop with a Connectify Wifi connection. The phone is at <code>192.168.156.112</code>. Now, I can access the service from the phone's browser with a URL such as <code>http://192.168.156.1:8080/lighting/12345</code>. However, when I try to access it from the app, i get a 'Connection Refused' error in LogCat. The following is the code i'm using to make the connection.</p>
  
  <pre><code>    String sampleURL = "`http://192.168.156.1:8080/lighting/weert`";
          HttpClient Client = new DefaultHttpClient();
           try
           {
               HttpGet httpget = new HttpGet(sampleURL);
               String serverString = "";
               HttpResponse response= Client.execute(httpget);
               StatusLine statusLine = response.getStatusLine();
               if (statusLine.getStatusCode() == HttpStatus.SC_OK) {
                   ByteArrayOutputStream out = new ByteArrayOutputStream();
                   response.getEntity().writeTo(out);
                   out.close();
                   serverString = out.toString();
               } 
               threadMsg(SetServerString);
            }
          catch(Exception ex){
              Log.e("RESTCALL",ex.getMessage());  
              threadMsg("Fail!");
           }
  </code></pre>
  
  <p>threadMsg() is the method that passes the response string back to the UI thread.</p>
  
  <p>Any help resolving this issue would be great! Thanks in advance!</p>
  
  <p>Update: Adding Stack Trace</p>
  
  <pre><code>    I/ActivityManager(  246): START {act=android.intent.action.MAIN cat=   [android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.testreceiver/.MainActivity u=0} from pid 464
      I/ActivityManager(  246): Displayed com.example.testreceiver/.MainActivity: +315ms
      W/System.err(15799): org.apache.http.conn.HttpHostConnectException: Connection to http://192.168.156.1:8080 refused
      D/AudioHardware(   89): AudioHardware pcm playback is going to standby.
      D/AudioHardware(   89): closePcmOut_l() mPcmOpenCnt: 1
      W/System.err(15799):    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:183)
      W/System.err(15799):    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
      W/System.err(15799):    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
      W/System.err(15799):    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
      W/System.err(15799):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
      W/System.err(15799):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
      W/System.err(15799):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465) 
      W/System.err(15799):    at com.example.testreceiver.MainActivity$1.run(MainActivity.java:47)
      W/System.err(15799):    at java.lang.Thread.run(Thread.java:856) 
      W/System.err(15799): Caused by: java.net.ConnectException: failed to connect to /192.168.156.1 (port 8080): connect failed: EHOSTUNREACH (No route to host)
      W/System.err(15799):    at libcore.io.IoBridge.connect(IoBridge.java:114)
      W/System.err(15799):    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
      W/System.err(15799):    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
      W/System.err(15799):    at java.net.Socket.connect(Socket.java:842)
      W/System.err(15799):    at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
      W/System.err(15799):    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
      W/System.err(15799):    ... 8 more
      W/System.err(15799): Caused by: libcore.io.ErrnoException: connect failed: EHOSTUNREACH (No route to host)
      W/System.err(15799):    at libcore.io.Posix.connect(Native Method)
      W/System.err(15799):    at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:85)
      W/System.err(15799):    at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
      W/System.err(15799):    at libcore.io.IoBridge.connect(IoBridge.java:112)
      W/System.err(15799):    ... 13 more
      E/RESTCALL(15799): Connection to `http://192.168.156.1:8080` refused
  </code></pre>
  
  <p>Also, here is the code that's running on the server.</p>
  
  <pre><code>    import socket
      from bottle import route, run@route('/lighting/&lt;name&gt;', method='GET')
  
      def hello(name="ABC"):
      return name
  
      run(host='192.168.156.1', port=8080, debug=True)
  </code></pre>