My app that is using Retrofit (v1.6.1) to connect to REST web services cannot connect to my local web server (running on localhost
), this is the error I am gett
On your phone connecting to localhost:3000
means "connect to port 3000 on local network interface" - which is local interface of the phone, not the port 3000 of the PC to which your phone is connected. There is nothing listening on port 3000 on the phone, so you get connection refused error.
Whould you're trying to do is (probably, hard to guess without more information) is to connect from the phone to port 3000 on you PC. So you should change the address you're connecting to from localhost
to address of the PC. In case of emulator that would be 10.0.2.2 (which is localhost of the PC). See networking information for reference.
I solved the issue, need to use 10.0.2.2
instead of localhost
to connect to my local server.
Found it here - http://developer.android.com/tools/devices/emulator.html#networkaddresses