Saumik Bhattacharya Saumik Bhattacharya - 1 year ago 277
PHP Question

Connection to LocalHost/ from Android Emulator timed out

Although this question has been asked multiple times in StackOverflow and I went through many of them, still I couldn't resolve my issue or I am not able to find out the root cause of the issue. Hence, posting a new question.

Below are the list of links I went through --

  1. How to connect to my http://localhost web server from Android Emulator in Eclipse

  2. Accessing localhost:port from Android emulator

  3. How can I access my localhost from my Android device?

  4. how to connect localhost in android emulator?

Here goes my code --

protected Void doInBackground(Void... params)
HttpURLConnection connection = null;

URL url = new URL("");
connection = (HttpURLConnection)url.openConnection();

OutputStreamWriter output = new OutputStreamWriter(connection.getOutputStream());

HttpResult = connection.getResponseCode();

catch(Exception e)
return null;

I am trying to connect Android with MySQL database using PHP through WAMP server. The PHP file (user_registration.php) is being saved in the below path --


Now after executing the code, I am getting an error like " failed to connect to / (port 8080) after 720000000ms: isConnected failed: ETIMEDOUT (Connection timed out)".

I went through the particular link in order to resolve this issue --

Android connection to localhost

But could not understand how it has been resolved! :)

Can you please help me in this case? Please note I am using Android Studio for my build.

Thanks in advance!

Answer Source

I have figured out the reason why it was not working. There were two issues --

  1. The IP Address was not correct. So I changed the IP Address from to the IPv4 address.

  2. Also the port number 8080 was not correct. I have set my own port number in httpd.conf file, like ##Listen [::0]:8383##, under Apache and I used the same.

After changing both and re-starting the WAMP server, it worked like a charm.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download