Skip to content

Raw sockets sample issue #20

@asimaranov

Description

@asimaranov

The ktor plugin generates the follow code as a raw sockets sample. It doesn't seem to work. The blocking operation happens without Dispatchers.IO context. The launch block is never started

object Client {
        @JvmStatic
        fun main(args: Array<String>) {
            runBlocking {
                val socket = aSocket(selectorManager).tcp().connect("127.0.0.1", port = DefaultPort)
                val read = socket.openReadChannel()
                val write = socket.openWriteChannel(autoFlush = true)

                launch {
                    while (true) {
                        val line = read.readUTF8Line()
                        println("server: $line")
                    }
                }

                // No Dispatchers.IO context !!!!

                for (line in System.`in`.lines()) {
                    println("client: $line")
                    write.writeStringUtf8("$line\n")

                }
            }
        }

        private fun InputStream.lines() = Scanner(this).lines()

        private fun Scanner.lines() = sequence {
            while (hasNext()) {
                yield(readLine())
            }
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions