Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connection to localhost:3000 refused on Android device

I am trying to connect to the restful web service i created through rails from my android app.

When I try to connect to the REST API deployed on http://localhost:3000 I get this error:

Connection to http://localhost:3000 refused.

I am running ubuntu natty narwhal.

Hitting this URL via a browser gets the response properly.

How can this be solved?

like image 942
rogerstone Avatar asked May 30 '11 21:05

rogerstone


1 Answers

If you are testing your app on your device then localhost is the device itself. If you are testing in the emulator then take a look at this document

If you need to refer to your host computer's localhost, such as when you want the emulator client to contact a server running on the same host, use the alias 10.0.2.2 to refer to the host computer's loopback interface. From the emulator's perspective, localhost (127.0.0.1) refers to its own loopback interface.

In your case your app/activity is trying to connect on port 3000 to your device not to your host computer.

like image 113
thomas Avatar answered Oct 03 '22 02:10

thomas