My local API setup is running in localhost:3000
on my Windows 10. I am using Retrofit to connect with APIs. I used http://10.0.2.2:3000
for connecting Android emulator to Window’s localhost. It was working fine for several months. One day it stopped working and I tried so many Google/Stackoverflow posts, but nothing helps. I tried in another newly installed machine and was not working. One day surprisingly it started working without any changes. Now I got my new PC and it is not working. Seems some instability with the 10.0.2.2 trick. Any ideas?
I am getting the below exception
java.net.SocketTimeoutException: failed to connect to /10.0.2.2 (port 3000) from /10.0.2.16 (port 51498) after 60000ms
2
Answers
Well, as you are asking for ideas, I am not sure if it’s work or not, but if I was working on this issue, probably my first step would be to update the retrofit for the last version, it seems the last version is
Version 2.9.0 (2020-05-20)
.If it’s not working or I can update it, I would fake a DNS in Windows.
To do that, I would include a new IP address in
c:WindowsSystem32Driversetchosts
:I hope it helps, but if not, give more context for non-android developers to try to help you, as I’m trying now.
So, it seems the problem is not in the server. So let’s check what could be in the android app.
Did you check:
AndroidManifest.xml
file:http://
URL, and your app’s targetSDK is 28 (Android 9.0)
or above, Android’s default network security policy will block your connection. You can enable clear text traffic for your domain in your app’snetwork_security_config.xml
:and
If it’s not work, could you set the
retrofit
to log the network request ?