Ming Zhu
Ming Zhu

Reputation: 282

Will mobile device network switch affect http communication?

For mobile Apps, it is a valid assumption that the network may be intermittent, or it may switch from one to another as the user keeps moving. For example, your device is connected to a startbucks wifi and you are using the App before you grab your coffee and walk out of the store -> Your mobile device network may switch from wifi to carrier network, 3G/4G/LTE. Even with the carrier network itself, it may switch among 3G/4G/LTE depending on their coverage at your position.

Question, Will this intermittent network, or frequently network switch affect the http communication? For example, an http request was sent out with Wifi, and while the server is processing the request, the device already switched to 4G. Will the device still be able to receive the response? If Yes, how is Http or TCP designed to support this scenario? If No, should we try to solve the problem from the application layer? and How?

Upvotes: 1

Views: 265

Answers (1)

shaochuancs
shaochuancs

Reputation: 16246

Will the device still be able to receive the response?

For current practice, No. After network is switched:

  1. Device's public IP address is changed.
  2. TCP connection is based on IP protocol, so all current TCP connection would be destroyed.
  3. HTTP is based on TCP connection, so it would be destroyed too.

Actually, you can make a simple experiment to verify this: Put a web page on internet and make the web server delay the page delivery for 30 seconds. Visit this page and switch network while waiting for the response.

However, this is a classic problem in mobile world, so some work is doing to give mobile device a constant IP, which will keep TCP&HTTP alive when device switches from one network to another. You can check Mobile IP in wikipedia for more information on various technologies and protocols.

If No, should we try to solve the problem from the application layer?

It depends on whether you can tolerate network interruption for your application. If it is a static web page, I think it is totally OK to leave this problem alone, and wait for Mobile IP technology improvement in future. If it is a highly network-dependent application, such as online video or stock market app, I think this problem should be solved in application layer.

and How?

There are 3 methods to fix/workaround this problem (maybe more):

  1. Cache. Prefetch resources, so that when TCP connection is destroyed and reconnected, device can use cached resources. This works well in online audio/video apps, but it does not apply when no resource can be prefetched (realtime stock market data for example).
  2. Take TCP re-connection as first priority. Check your code, when HTTP failed due to destroyed TCP connection, re-send HTTP request as early as possible.
  3. Improve user experience when network interruption do happens.

Upvotes: 2

Related Questions