Search code examples
kotlinktorkotlin-native

Kotlin/Native can't import io.ktor.network.selector.ActorSelectorManager


I want to use TCP Sockets in Kotlin/Native using KTOR and I followed the according tutorial. But somehow I can't import ActorSelectorManager from io.ktor.network.selector and get Unresolved reference: ActorSelectorManager

My build.gradle.kts looks like this:

plugins {
    kotlin("multiplatform") version "1.4.32"
    kotlin("plugin.serialization") version "1.4.32"
}
repositories {
    mavenCentral()
    jcenter()
    maven { url = uri("https://plugins.gradle.org/m2/") }
    maven { url = uri("http://dl.bintray.com/kotlin/kotlin-dev") }
    maven { url = uri("https://kotlin.bintray.com/kotlinx") }
}

kotlin {
    val hostOs = System.getProperty("os.name")
    val isMingwX64 = hostOs.startsWith("Windows")
    val target = when {
        hostOs == "Mac OS X" -> macosX64("SocketStuff")
        hostOs == "Linux" -> linuxX64("SocketStuff")
        isMingwX64 -> mingwX64("SocketStuff")
        else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
    }

    target.apply {
        binaries {
            executable {
                entryPoint = "main"
            }
        }
    }

    sourceSets {
        val Main by getting
        val Test by getting
        commonMain {
            sourceSets["commonMain"].dependencies {
                implementation("io.ktor:ktor-network:1.5.3")
            }
        }
    }
}

Does anyone know if I forgot to add a dependency or something?


Solution

  • There are the ActorSelectorManager on the JVM and the WorkerSelectorManager on the native target. You can use constructor function SelectorManager() to instantiate appropriate selector manager instance:

    import io.ktor.network.selector.*
    
    fun main() {
        val manager = SelectorManager()
    }