Hi everyone, help needed for WebSocket server in K...
# ktor
a
Hi everyone, help needed for WebSocket server in Ktor. Any experts here? I have this code from Ktor github code sample:
Copy code
fun main(args: Array<String>) {
    runBlocking {
        val selectorManager = SelectorManager(<http://Dispatchers.IO|Dispatchers.IO>)
        val serverSocket = aSocket(selectorManager).tcp().bind("127.0.0.1", 9002)
        println("Server is listening at ${serverSocket.localAddress}")
        while (true) {
            val socket = serverSocket.accept()
            println("Accepted $socket")
            launch {
                val receiveChannel = socket.openReadChannel()
                val sendChannel = socket.openWriteChannel(autoFlush = true)
                sendChannel.writeStringUtf8("Please enter your name\n")
                try {
                    while (true) {
                        val name = receiveChannel.readUTF8Line()
                        sendChannel.writeStringUtf8("Hello, $name!\n")
                    }
                } catch (e: Throwable) {
                    socket.close()
                }
            }
        }
    }
}
But when I try to connect it to it from Postman on
<wss://127.0.0.1:9002>
I’m getting
Error: write EPROTO 140509838351224:error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER:../../../../src/third_party/boringssl/src/ssl/tls_record.cc:242:
Any help really appreciated. Thanks!
a
This code starts a server that listens to TCP/IP connections. Here you can find a WebSockets server example.
a
Thanks! I changed the implementation and I’m still getting the same error. The server is run at
0.0.0.0:8080
and I’m connecting to
wss:\\0.0.0.0:8080\echo
with Postman when I get the error. Maybe my computer is missing some libs.
I should have used
ws:\\0.0.0.0:8080\echo
instead since there is no SSL configured. Thanks @Aleksei Tirman [JB] again for pointing in right direction.