I'm using ktor 2.0.3 in my Android app with the CI...
# ktor
z
I'm using ktor 2.0.3 in my Android app with the CIO engine. I've found that in the emulator I get a crash when trying to make a request to
<https://youtube.com>
but not when I make a request to another URL such as
<https://github.com>
On an actual phone this crash doesn't happen. The code im using is this in my MainActivity
Copy code
HttpClient(CIO).get("<https://youtube.com/>")
The crash
Copy code
Caused by: java.net.SocketException: Network is unreachable
	at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
	at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:762)
	at io.ktor.network.sockets.SocketImpl.connect$ktor_network(SocketImpl.kt:50)
	at io.ktor.network.sockets.SocketImpl$connect$1.invokeSuspend(Unknown Source:15)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
	at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
	at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:749)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
a
Could you please try to make a request with another HTTP client to https://youtube.com? Do you get the similar error?
z
Another engine you mean?
a
I mean another client, like HttpURLConnection.
z
Ah ok, one moment
Same thing
Copy code
val connection = URL("<https://www.youtube.com>").openConnection() as HttpURLConnection
val body = connection.inputStream.bufferedReader().readText()
a
Are you able to access https://www.youtube.com from your host machine?
z
Yes
a
I guess this problem is related to Android emulator settings.
z
Though I am able to access https://www.youtube.com just fine in chrome on the emulator