kotlin SocketTimeoutException: failed to connect to /10.0.2.2 (port 3000) from /192.168.0.66 (port 35314) after 10000ms

Viewed 681

This has been posted a lot but I haven't come across any solution that would work for me. I have a Flask server + Kotlin client. I am trying to do simple get request from my local rest Api. what i did:

1 Devices are on the same Wifi, (checked in ipconfig)
2 I checked the ipv4 on ipconfig (it's the same)
3 I tried running my phone on mobile hotspot and then accessing URL
4 I tried adb reverse.
5 I tried disabling windows10 firewall it didn't help.

I works on my emulator but not on the device. This is my .kt file

class Constants {

    companion object{

        const val BASE_URL = "http://192.168.0.185:3000"

    }
}

All the code is available here on my previous post ->
flask + retrofit in kotlin cannot acces API endpoint with IP address (Failed to connect to /127.0.0.1:5000)

enter image description here

What else can I do?

1 Answers

To fix it it's necessary to ad "/" in .baseUrl()

private val retrofit  by lazy {
    Retrofit.Builder()
        .baseUrl(BASE_URL + "/")
        .addConverterFactory(GsonConverterFactory.create())
        .build()

}
Related