0

I am creating a class which communicates with remote server. Currently my device (iPhone 4) is having connectivity via wifi and local network cellular. By default it uses wifi. It works fine in both the cases.

However when I switch from wifi to cell service, it hits error delegate. I want keep communication on going even when connectivity is changed.

Is it possible? How? Thanks,

Apurv
  • 17,116
  • 8
  • 51
  • 67

1 Answers1

1

I don't expect it is possible. Having switched networks, you've probably also switched IP addresses. Connections are defined by the IP addresses of the end points (as well as protocol and protocol-specific data such as port numbers). So, you can't maintain a connection when the IP address changes. You must cleanup and dispose of the broken connection and open a new one.

If the high-level protocol you're using, such as FTP or HTTP, allows it, you can try resuming the data transfer at the point it was interrupted. For example, if downloading a file, you may be able to resume the download at the file position of the last data you received.

Ken Thomases
  • 88,520
  • 7
  • 116
  • 154
  • Thanks. +1 for that. Can I check the change in IP addresses? Also, do you know any familiar library which supports resuming of uploading/downloading in such kind of circumstances? – Apurv Jun 18 '12 at 05:44
  • You're welcome. I don't know of a library to handle resuming, but I don't think it's very complicated. For HTTP, I suspect it's just a matter of setting a header on the `NSURLRequest`. As for tracking the change of IP address, I recommend [Technical Note TN1145: Living in a Dynamic TCP/IP Environment](https://developer.apple.com/library/mac/#technotes/tn1145/_index.html). It has a lot of legacy references and is Mac-centric, but the principles still apply. – Ken Thomases Jun 18 '12 at 14:55