Jump to content
Bilcan

Switching from Wi-fi to Mobile Data raise disconnect at Indy

Recommended Posts

Switching from wi-fi to mobile data in an Android app raises a disconnect, but on Windows, the same application does nothing when I switch-off wifi, which is what I want exactly. So am I missing something on the Android side?

 

Delphi 12

Indy 

Share this post


Link to post

No. The connection has to be disconnected and reconnected, it can't be moved from one network to another.  Android is doing the right thing.
 

https://android.stackexchange.com/questions/83830/how-can-android-keep-a-tcp-connection-alive-when-changing-network-provider

 

I would question why Windows is not doing the same thing, as it should be.  Maybe your code is just not doing anything that triggers a disconnect during a network change?  On both platforms, you might consider having your app register with the OS to receive network change notifications.

  • Like 1

Share this post


Link to post
Quote

I would question why Windows is not doing the same thing, as it should be.  Maybe your code is just not doing anything that triggers a disconnect during a network change?  On both platforms, you might consider having your app register with the OS to receive network change notifications.

I just turn off the wifi, wait for a while, then turn it on again, so maybe this is not a network change for the Windows OS.

 

Quote

No. The connection has to be disconnected and reconnected, it can't be moved from one network to another.  Android is doing the right thing.

Thank you for the clarification. @Remy Lebeau

Share this post


Link to post
23 minutes ago, Bilcan said:

I just turn off the wifi, wait for a while, then turn it on again, so maybe this is not a network change for the Windows OS.

Quite possibly.  Keep in mind that TCP is resilient to temporary network outages, so as long as the WiFi maintains the same IP when it comes back on, previous TCP connections may be recoverable by the OS if it hasn't invalidated them yet.

 

On the other hand, if your code is not reading/writing data with the connection during the time that the WiFi is turned off, then it makes sense that you won't see a disconnect.  It can take time for a lost connection to be detected.  If the OS's internal timeout is not to your liking, you might consider enabling TCP keep-alives on the connection.

 

  • Like 1

Share this post


Link to post

Thank you for the answers, I understand the issue better now.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×