简体   繁体   中英

Connecting Android client to a Java servlet via wifi

I am following this tutorial to implement this: http://www.veereshr.com/Android/AndroidToServlet

I got my server up and running and I am able to open its localhost link in my browser. However, when I run the Android app on my Nexus 5, I get this error:

11-26 01:34:46.501 1092-1340/com.example.nav.wificlient D/Exception:java.net.ConnectException: failed to connect to /10.0.2.2 (port 8080): connect failed: EHOSTUNREACH (No route to host)

11-26 01:35:29.171 1092-1557/com.example.nav.wificlient D/Exception: java.net.ConnectException: failed to connect to /10.0.2.2 (port 8080): connect failed: ETIMEDOUT (Connection timed out)

Both my laptop (which is running the server program) and my phone are connected to the same network (called eduroam) on a college campus. I made sure that my firewall settings are not blocking incoming connections on my laptop.

I'm wondering if maybe the campus network settings are blocking this somehow...but I'm not sure. Any ideas on how I can narrow down what may be going wrong?

10.0.2.2 is a unique address directly interpreted by the emulator to reference the machine running the emulator. This is useful as "localhost" would simply reference the emulator itself.

As you are not running your android application on an emulator, but rather an actual device, you need to change your application so that, instead of connecting to 10.0.2.2, it connects to the local IP of the computer hosting the server.

See here for more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM