Skip to content

Commit 1e4dab1

Browse files
author
Robert Meijers
committed
try reconnecting after link properties changed
In some circumstances (like the server only being reachable over IPv6) reconnecting when the network becomes available doesn't work. This due to the network only being "partially" available (in the example: IPv4 working, but IPv6 not yet). By also listening for changes of the link properties a new connection attempt is made when for example the IP addresses of the link, or the networking routes change. Meaning that the example issue is fixed, as a new attempt is made after the IPv6 address is set on the link / the routes for IPv6 networking are available.
1 parent cd7ac55 commit 1e4dab1

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

app/src/main/kotlin/com/github/gotify/service/WebSocketService.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import android.content.Intent
99
import android.content.pm.ServiceInfo
1010
import android.graphics.Color
1111
import android.net.ConnectivityManager
12+
import android.net.LinkProperties
1213
import android.net.Network
1314
import android.os.Build
1415
import android.os.IBinder
@@ -57,6 +58,12 @@ internal class WebSocketService : Service() {
5758
Logger.info("WebSocket: Network available, reconnect if needed.")
5859
connection?.start()
5960
}
61+
62+
override fun onLinkPropertiesChanged(network: Network, linkProperties: LinkProperties) {
63+
super.onLinkPropertiesChanged(network, linkProperties)
64+
Logger.info("WebSocket: Network properties changed, reconnect if needed.")
65+
connection?.start()
66+
}
6067
}
6168
private val appIdToApp = ConcurrentHashMap<Long, Application>()
6269

0 commit comments

Comments
 (0)