Connection to LocalHost/10.0.2.2 from Android Emulator timed out

Connection to LocalHost/10.0.2.2 from Android Emulator timed out

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Connection to LocalHost/10.0.2.2 from Android Emulator Timed Out

When developing an Android app that communicates with a local server running on your development machine, you often encounter connectivity issues. A common scenario involves using a WAMP or XAMPP stack on Windows and attempting to reach http://localhost from the Android emulator. If you are seeing a java.net.SocketTimeoutException specifically mentioning 10.0.2.2, the root cause is almost certainly a misunderstanding of how network addresses map between the host and the guest environment.

The error message indicates that the emulator tried to connect to 10.0.2.2 on port 8080 but timed out after 720,000,000 milliseconds (which is roughly 200 hours). This timeout duration suggests the connection attempt was made, but no response was received before giving up. The immediate assumption might be that the server isn't running or that the port is wrong. However, in this specific topology, the address 10.0.2.2 is a special alias provided by the Android emulator that maps directly to your host machine's loopback interface (localhost).

Your code snippet correctly identifies 10.0.2.2 as the target IP for the WAMP server. The critical issue lies in the port configuration. You defined the URL as http://10.0.2.2:8080. By default, WAMP servers run on port 80, but if you are using a specific port like 8080, you must ensure that:

  1. The Apache/Nginx configuration explicitly listens on that port.
  2. Windows Firewall or other security software is not blocking inbound connections on that specific port from the host network interface.
  3. The WAMP setup is actually bound to the loopback address (127.0.0.1) rather than just localhost in a way that rejects external (even local) IP traffic, though usually, binding to * or 0.0.0.0 is safer for this use case.

If your WAMP server is strictly bound to 127.0.0.1:8080, the emulator should still be able to reach it via 10.0.2.2. However, if the connection times out immediately, verify that the port 8080 is actually listening on your Windows host machine. You can do this by opening a command prompt on your PC and running:

netstat -ano | findstr :8080

If no process is listening, your web server configuration is incorrect. If a process is listening, ensure that the firewall allows traffic on port 8080. Sometimes, developers mistakenly think they need to change the IP address inside the emulator code, but 10.0.2.2 is hardcoded by the Android emulator's networking layer specifically for this purpose. Changing it to your actual Windows IP address (e.g., 192.168.1.5) will fail if that IP is not publicly routable or if the firewall blocks private subnet access from outside.

Another subtle pitfall involves the timeout values in your Java code. You set setConnectTimeout(720000000). While this seems like a long time, network environments can be unstable. However, the primary failure here is likely that the socket never establishes a handshake, causing the timer to expire eventually. It is often better to reduce the timeout slightly (e.g., 30,000 ms or 30 seconds) to fail fast and get a clearer error message if the connection truly cannot be established.

If you are switching environments, such as moving from a local development setup to a production server, remember that 10.0.2.2 will not work on real devices or emulators running on non-Windows hosts (like macOS or Linux). On those systems, you must use the actual hostname or IP of your development machine. For robust applications hosted on Laravel or similar frameworks, ensure your APP_ENV is set correctly and that your virtual host configuration points to the correct domain rather than relying on localhost aliases.

Finally, always check your WAMP status indicator. If it shows "OFF," no service is listening regardless of the code logic. Once the server is running, the port is open, and the firewall is configured, the connection via 10.0.2.2 should succeed without requiring any code changes to the IP address itself.

Our network