Anyone still uses it? Why?
# ktor
o
Anyone still uses it? Why?
t
i've had people request support for SSE for javalin too, claiming "it works better" than websockets
no one has presented a convincing argument though
o
I hope eventually websockets will be replaced by HTTP/2. Thinking about API that would be the same, but can be bound to either WS or HTTP/2 channels
l
I don't think I specifically need SSE. I've never needed push events of any kind. I'm developing an internal tool (code analysis and compiling) and I thought it would be nice to get progress report from my parsing/compiling back-end stages (they take some time).
so, any tips on websockets for console-like output, I'm all ears 🙂
o
On server side it’s really easy.
Copy code
val messages = ConflatedBroadcastChannel<String>() // local message bus

// where you've got message
messages.offer(message) // send a string to channel's subscribers

// inside your routing
webSocket("ws") {
        messages.openSubscription().use { subscription -> // subscribe to channel
            subscription.consumeEach { // on each message
                outgoing.send(Frame.Text(it))) // send message as text frame to any connected websocket client
            }
        }
    }
Ah, and you’ll need to
install(WebSockets)
in your app
l
Thank you, I'll check this out