I am using ktor version `2.3.9` to establish web ...
# ktor
k
I am using ktor version
2.3.9
to establish web socket connection, but when the connection is established and I keep on minimising and maximising my application, after some times it auto breaks the connection with the following message to my backend.
disconnectReason: "Connection closed abnormally"
I don't get it any where in logs on my side. It is happening on both android and ios. If I keep the application in foreground, everything keeps on working as it should without any issues. Any ideas why this is happening???
a
It's difficult to say. Can you try setting the ping interval (https://ktor.io/docs/client-websockets.html#configure_plugin), so the connection could be kept alive?
k
I already have it set to 20 seconds.
@Kashismails
s
after some times it auto breaks the connection
@Khanzada Kashif how much time? I do not know about iOS, but in Android the system can kill applications that are in the background to give resources to the one that is in the foreground. If you need to keep a long-lived connection, even if you app is in the background, you need to use something like a ForegroundService.