https://kotlinlang.org logo
Title
d

Dragos Rachieru

01/07/2021, 11:36 AM
Do websockets work in 1.5.0? I am sending a Frame, but the client is not receiving it.
@JvmStatic
    fun main(args: Array<String>) {
        println("config sockets")
        val client = HttpClient {
            install(WebSockets)
        }
        println("starting")
        runBlocking {
            <http://client.ws|client.ws>(
                method = HttpMethod.Get,
                host = "0.0.0.0",
                port = DefaultPort,
                path = "/game?access_token=$token&game_type=DUEL",
                request = {
                    header("Authorization", "Bearer $token")
                }
            ) {
                println("connected")
                GlobalScope.launch(<http://Dispatchers.IO|Dispatchers.IO>) {
                    while (true) {
                        val scanner = Scanner(System.`in`)
                        val command = scanner.nextLine()
                        send(Frame.Text("${ServerFrameKey.PLACE.key}:$command"))
                    }
                }
                // Receive frame.
                for (frame in incoming) {
                    when (frame) {
                        is Frame.Text -> println(frame.readText())
                        is Frame.Binary -> println(frame.readBytes())
                    }
                }
            }
        }
    }
This is the code for the client
fun send(session: WebSocketServerSession, command: CommandFrame<*>) {
    val text = commandProcessor.process(command)
    session.launch {
        session.send(Frame.Text(text))
        println("sent $text")
    }
}
this is how i send data to the client
i get
sent connected_room:60
in logs, but client prints nothing
it might be a problem with okhttp
cio seems to work
c

Chris Fillmore

01/07/2021, 8:25 PM
fwiw I am using 1.5.0 with okhttp websockets and it’s working for me
d

Dragos Rachieru

02/01/2021, 7:53 AM
it didn't for me, switched to CIO, all good