Home > database >  Failed Connect Local Host (Desktop)
Failed Connect Local Host (Desktop)

Time:10-08

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)

CodePudding user response:

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/"

CodePudding user response:

It can be that firewall on your pc blocks the connection.

Or you have bound your server to localhost/127.0.0.1.

Do not bind your server to an ip address.

  • Related