Sam YC
Sam YC

Reputation: 11617

Will http resume after network down?

I am testing Http connection and I found that the behavior is weird. I want to test whether the http connect will continue after network is enabled/disabled. The only way for me to test this is to disable the network adapter.

For example, before I press the button to startup a http connection, I disable the network adapter first, after the code perform http.connect(), I re-enable the network adapter back (within the allowed timeout), but at last, the timeout still thrown, I thought the connect will be still valid before timeout ?

How do you all handle this issue since nowadays mobile app (android, IOS) will need to overcome a lot of network down when 3G is not available for a short-while.

Upvotes: 3

Views: 242

Answers (1)

Dirk Stöcker
Dirk Stöcker

Reputation: 1638

Yes and no.

Actually this depends on so many different components that an answer is very hard.

One working example: Consider a network connection is established, then it goes down and is restarted. Still there are packets on the way and reach the target after restart. Now it is possible that the error correction systems in TCP simply catches up and connection goes on. Remove Ethernet cable from a computer and reconnect it some seconds later and you will see this works. BUT: Usually mobile devices get a new IP for reconnects which makes that impossible.

In between your device and the network are many components including routers, transparent proxies, firewalls and so on. All of these have different timeouts, some sent messages which can stop or drop connections, some don't. Some even block such messages. So while it is possible it is not reliable.

Your example: When you do a connect() when the network is down, I would expect an immediate refusal usually. But maybe DNS causes a delay here, so you get a timeout instead. I doubt there are cases where a connect() during a downtime will continue by itself when line is online again.

Upvotes: 1

Related Questions