Connection to LocalHost/10.0.2.2 from Android Emulator timed out
Accepted answer to this question is really unclear so maybe this will help someone.
Just got the same problem and resolved it by executing "adb reverse tcp:8080 tcp:8080", although after I revoked forwarding, the host machine remained visible and all ports were working, so it is unclear how it works.
Make sure that
- you have no proxy in wifi settings
- if you have, then 10.0.2.2 is added to bypass without mask
- that you didn't make a typo, sometimes people put 0 instead of 2 like this 10.0.0.2:8080
Why to go for localhost or any ip address to run on emulator or real device simply go for ngrok to convert the localhost as a global address with very convenient and simplest way.
Making a connection from your Android to your Computer is working with 10.0.2.2 only on an Google Android Virtual Device. Android Virtual Devices are listening for 10.0.2.2 and forwarding all the requests to your computer.
Genymotion Android Virtual Devices are listening on 10.0.2.3 and forwarding those requests to your computer.
10.0.2.2 is not working with your real Android device. If you want to use it with your real device you have to set the IP of your computer, as it has been suggested by a previous answer.
I have figured out the reason why it was not working. There were two issues --
The IP Address was not correct. So I changed the IP Address from
10.0.2.2
to theIPv4
address - which can be obtained on windows by typeingipconfig
in the command prompt and see link for linux.Also the port number 8080 was not correct. I have set my own port number in
httpd.conf
file, like##Listen 12.34.56.78:8383Listen 0.0.0.0:8383Listen [::0]:8383##
, under Apache and I used the same.
After changing both and re-starting the WAMP server, it worked like a charm.