0

I have an Android application that connects to a servlet in a Tomcat server.

I have Tomcat server coupled to eclipse.

The IP address indicated to the Android application to connect to the Tomcat servlet is

http://10.0.2.2:8080/Middleware/UsuarioServlet

Why if I put

http://localhost:8080/Middleware/UsuarioServlet

not work and gives an error? If I have installed Tomcat on the same machine should work with localhost too.

F3RN1
  • 179
  • 2
  • 6
  • 14
  • Have a look at this question -> http://stackoverflow.com/questions/5806220/how-to-connect-to-my-http-localhost-web-server-from-android-emulator-in-eclips – Lars Juel Jensen Apr 29 '13 at 20:18

2 Answers2

2

Because your Android application runs on virtual device, which has another IP in your local intranet, it isn't localhost.

Andremoniy
  • 34,031
  • 20
  • 135
  • 241
1

Localhost refers to the Android device in this case. Use the IP address 10.0.2.2 to refers to your development machine. Read more about here!

Rodrigo Villalba Zayas
  • 5,326
  • 2
  • 23
  • 36