Hello. I'm new at Ktor and I get an error ->"io.kt...
# ktor
h
Hello. I'm new at Ktor and I get an error ->"io.ktor.client.network.sockets.ConnectTimeoutException: Connect timeout has expired [url=http://ip:8080/auth/login, connect_timeout=unknown ms]". What is the reason? The code is the following:
Copy code
val ktorHttpClient = HttpClient(CIO) {

    install(WebSockets)

    install(ContentNegotiation) {
        json(Json {
            prettyPrint = true
            isLenient = true
            ignoreUnknownKeys = true
        })
    }

    engine {
        requestTimeout = 60_000L
    }

    install(Logging) {
        logger = object : Logger {
            override fun log(message: String) {
                Log.v("Logger Ktor ->", message)
            }
        }
        level = LogLevel.ALL
    }

    install(ResponseObserver) {
        onResponse { response ->
            Log.d("Http status:", "${response.status.value}")
        }
    }

    install(DefaultRequest) {
        header(HttpHeaders.ContentType, ContentType.Application.Json)
    }
}
On Postman the link works properly.
e
Hi John, I see in the url that you provided a
connect_timeout=unknown ms
is this intentional? Morover, this seems to be the code to set up the http client. Do you also have some code that makes the actual request?
h
Hi @Erwin Kok The request works on an emulator, but on my phone it doesn't work. But when I disable Firewall, it works on my phone. How can I fix solve the issue.
a
You might need to add an exception rule to the firewall.