Failed Connect Local Host (Desktop)

Issue

Hi using retrofit api call method but am using local ip address still am not get proper response. if i tested in postman i got correct json response but in android studio am facing this connection issue.

Error…>
HTTP FAILED: java.net.SocketTimeoutException: failed to connect to /192.168.1.52 (port 5000) from /192.168.1.54 (port 58978) after 60000ms: isConnected failed: ETIMEDOUT (Connection timed out)

Solution

I had this problem before and I remember that if you have your server running in the same network as the app you need to use 10.0.2.2:{PORT} or the laptop network IP (in case you run it on a real device).

So your endpoint in your case should be :

//For real device
private const val BASE_URL = "http://192.168.1.51:5000/"
//For emulator
private const val BASE_URL = "http://172.0.2.2:8080/"

Check please that is not problem with your Firewall sometimes you have to allow access (restarting PC would be enought to know if it’s the problem)

Answered By – Skizo-ozᴉʞS

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published