I can only subscribe to the message event
webSocket("api") {
incoming.consumeEach { frame ->
when (frame) {
is Frame.Close -> println("close") // not work
is Frame.Binary -> {
val length = frame.buffer.remaining()
val byteArray = ByteArray(length)
frame.buffer.get(byteArray)
val request = Mapper.mapTo<Request<Any>>(byteArray)
}
}
}
}
Such an opportunity will be in the future?
incoming channel simply gets closed, a close reason could be obtained from closeReason deferredincoming channel gets closed with error (attempt to receive on this channel will cause it to throw an exception) and/or closeReason could be completed with the reason@cy6erGn0m Thanks for the answer, there are few examples and information on the websocket in the documentation
@soywiz Since this approach looks different too the classic approach we probably can add a small notice at our page http://ktor.io/servers/features/websockets.html
@soywiz Since this approach looks different too the classic approach we probably can add a small notice at our page http://ktor.io/servers/features/websockets.html
This link is dead now. But the content is available here: https://ktor.io/docs/websocket.html#standard-events
Oh thank you.
Most helpful comment
@soywiz Since this approach looks different too the classic approach we probably can add a small notice at our page http://ktor.io/servers/features/websockets.html