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

gotoOla

05/17/2019, 3:28 PM
Hi! Is there anyway to get notified on onClose-events when using websockets? I recon that you get a ClosedReceiveChannelException when you try to sendto a closed channels but I would like to get triggered as soon as a client disconnects. The Frame.Closed only seems to be sent if the user actually closes, not if they crash
c

cy

05/17/2019, 3:38 PM
incoming channel gets closed in any case, it is closed immediately when a disconnect is detected
g

gotoOla

05/17/2019, 3:58 PM
@cy that is nice, in my case I have a set of OutgoingChannels though, so if a user get’s disconnected I want to remove them from that set, am I approaching it the wrong way?
Copy code
private val connectedPeers = mutableSetOf<SendChannel<Frame>>()
.
.
.
webSocket(prefix) {
                try {
                    peersMutext.withLock {
                        connectedPeers.add(outgoing)
                    }
....
....
}
so basically I want to know when I should/could do a connectedPeers.remove
2 Views