https://kotlinlang.org logo
#ktor
Title
# ktor
t

thana

05/06/2022, 6:59 AM
Is there a major design flaw in the websockets client api, or am i missing something? you can call
receiveDeserialized
on the
DefaultClientWebSocketSession
but sooner or later this will inevitably result in an exception: as soon a Ping or a Close frame arrives this fails. Wouldn;t you actually need something like
frame.readDeserialiing()
or similar, so you could write something like
Copy code
for(frame in incoming){ 
  when(frame.frameType)  {
   FrameType.TEXT -> frame.readDeserialzied()
   FrameType.CLOSE -> return;
}
}
?
e

e5l

05/06/2022, 7:00 AM
Hi @thana, it’s not expected to receive
PING
or
Close
in the default client session. They are handled automatically
t

thana

05/06/2022, 7:06 AM
Hm ok. But i always get this exception in the console
Converter doesn't support frame type CLOSE
e

e5l

05/06/2022, 7:07 AM
That’s strange, could you log an issue with reproducer? I will take a look
t

thana

05/06/2022, 7:07 AM
maybe i'm misinterepting the situation because i wrote
while(true){receiveDeserialized()}
and
true
is jjust a bad choice for rhe loop 😄
e

e5l

05/06/2022, 7:08 AM
Thats fine. The
CLOSE
frames should be filtered out any way
t

thana

05/06/2022, 7:12 AM
what would be the expected outcome when reading from a closed websocket session in an infinite loop? 🤔
a

Aleksei Tirman [JB]

05/06/2022, 10:13 AM
You are right about
receiveDeserialized
in a way that it shouldn’t receive a frame, otherwise responsibilities for receiving and deserialization are mixed in this method and that leads to the problem you described.
29 Views