Sample Ktor websocket project, both client and ser...
# ktor
s
Sample Ktor websocket project, both client and server are 2.3.11. Client sends binary frames with fin=false, server receives fin=true. I have traced this to using ktor-client-okhttp, cio works as expected. is this a known bug?
a
Do you mean the Chat sample? What must be changed there to reproduce the bug?
s
No I meant my own sample. Server:
Copy code
routing {
        webSocket("/ws") { // websocketSession
            for (frame in incoming) {
                if (frame is Frame.Binary) {
                    val bytes = frame.readBytes()
                    println("Received ${bytes.size} fin ${frame.fin}")
                }
            }
        }
    }
Client:
Copy code
runBlocking {
        client.webSocket(HttpMethod.Get,
            "localhost",
            8080,
            "ws",
            request = {
                headers {}
                url.protocol = <http://URLProtocol.WS|URLProtocol.WS>
            }
        ) {
           send(Frame.Binary(false, ByteArray(10))
...
Here is the client build:
Copy code
product: jvm/app

dependencies:
  - io.ktor:ktor-client-core:2.3.11
  - io.ktor:ktor-client-okhttp:2.3.11
  - io.ktor:ktor-client-websockets:2.3.11

settings:
  kotlin:
    languageVersion: 1.9
If ktor-client changes to ktor-client-cio the bug disappears
There is also another bug on top of that, also happen with okhttp client only. If I send a lot of data without acknowledgements, the packets stop arriving at the destination as soon as the amount sent is larger than 16mb.
a
I've reproduced the problem. I guess it's a limitation of the OkHttp client because their Websocket.send method doesn't accept the
Fin
parameter. Also, the documentation says the following about your second problem:
Messages that would overflow the outgoing message buffer (16 MiB) will be rejected and trigger a graceful shutdown of this web socket.
Nonetheless, I can file the issues if you like.
s
Well, to me it doesn’t matter anymore, but I’d file an issue with OkHttp…