0

I'm trying to connect to localhost on Android Studio

I tried : localhost, 127.0.0.1, 10.0.2.2:8080

But I'm still getting the same response:

failed to connect to /10.0.2.2 (port 8080): connect failed: ECONNREFUSED (Connection refused)

I found online (Android connection to localhost) that in eclipse you should first bind the ip in eclipse settings.

But I can't figure out how to do the same in Android Studio

Community
  • 1
  • 1
gilad s
  • 475
  • 8
  • 16
  • yes.. actually I'm trying to figure out how to use a real device right now... any good links? – gilad s Jun 22 '14 at 09:45
  • You can't connect to your localhost using a real device. – Shivam Verma Jun 22 '14 at 09:47
  • OK - so I'll continue to use an emulator- but what should I do with this error message ? – gilad s Jun 22 '14 at 11:00
  • I did mention in my answer below how you can use the real device to connect with your localhost. The error message is coming probably because the address you are trying to use is unreachable. – Shivam Verma Jun 22 '14 at 11:02
  • I tried an external URL and it seems to work fine. So the problem is indeed restricted only to localhost. Localhost is reachable via web browser.. But I'll try what you suggested. Thanks – gilad s Jun 22 '14 at 11:18

1 Answers1

0

You can't connect to your localhost (127.0.0.1 or 10.0.2.2) using a real device. An easy solution is to make sure that your computer and android device are connected to the same network(WiFi / Host a hotspot) and then use the computer's IP Address to conect.

Shivam Verma
  • 7,973
  • 3
  • 26
  • 34