Help with Ktor (Raw sockets)


So, I was gonna make a small IRC client and thought about using Ktor as the networking library.I quickly followed the guide and made this small snippet as an example:

import kotlinx.coroutines.experimental.*

fun main(args: Array<String>) {
    runBlocking {
        val socket = aSocket().tcp().connect(InetSocketAddress("", 2323))
        val input = socket.openReadChannel()
        val output = socket.openWriteChannel(autoFlush = true)

        val response = input.readASCIILine()
        println("Server said: '$response'")

But the problem is that im getting a missing dependencies for the following:

~/Programming_Workspace/Ma_Currents/KtorExample/src/main/kotlin/com/otakusenpai/KtorExample/main.kt: (9, 22): Unresolved reference: aSocket
~//Programming_Workspace/Ma_Currents/KtorExample/src/main/kotlin/com/otakusenpai/KtorExample/main.kt: (2, 16): Unresolved reference: network

Can you guys please help me?


Also, IntelliJ isnt showing hints on the packages i should use. If it did so, then it could be done already.


Unresolved reference means that the variable isn’t defined. You probably meant to type “Socket” instead of “aSocket” or “ASocket”.

I can’t comment on what ktor package you should use, though.

EDIT: You should probably show off the contents of your build.gradle file or talk about how you’re trying to build it for that to be answered. The master branch of ktor makes it look like should be a valid package.

EDIT EDIT: Okay, I can reproduce this now that the build.gradle is out. It looks like aSocket is a special function in the Builders. I think it may be a matter of needing to include ktor-network in the build file.


Heres my build.gradle`


I think you need to include compile "io.ktor:ktor-network:$ktor_version" in your dependencies. That should resolve network being undefined.