hi, i've tried to find some propper way to clase a...
# ktor
s
hi, i've tried to find some propper way to clase a SSE connection, does anyone know how to do it? My BE allows only 5 parallel connections per customer, so its crucial to close connection as soon as user does not need it any more (leaves a chat screen for example). I have function like this (snippet below). But even after leaving "chat" screen, i still can debug events in OkHttpSSESession#onEvent
a
The SSE spec indicates that a client will attempt reconnection unless the server sends a HTTP 204: https://html.spec.whatwg.org/multipage/server-sent-events.html
a
Have you tried calling the
cancel
method on an
ClientSSESession
instance?
s
@Aleksei Tirman [JB], yeah, i updated my code like in screenshot#1. When i call
disconnect()
- when leaving a screen (log "_DEF-4305chatdisconnect"_ is printed as expected),
OkHttpSSESession
receives 8 events in
onEvent
(i'm sure its because of definition in
OkHttpSSESession
):
Copy code
private val _incoming = Channel<ServerSentEvent>(8)
But what is never called - is
OkHttpSSESession#onClosed
. It's a little bit suspicious.
Its a screenshot of
OkHttpSSESession
(ktor version 3.1.1) i refer to.
a
Can you please share a sample code snippet as text to reproduce the problem?