iOS: Keeping a loopback-only socket open across backgrounding?
iOS: Keeping a loopback-only socket open across backgrounding?
- Subject: iOS: Keeping a loopback-only socket open across backgrounding?
- From: Jens Alfke <email@hidden>
- Date: Tue, 09 Aug 2011 14:34:45 -0700
So, iOS closes all of an app’s open sockets when the app goes into the background. Is there any way to get local loopback sockets (i.e. those bound to 0.0.0.0) to not close?
This is proving problematic for CouchDB, which fundamentally has a client/server architecture based on HTTP. We’re running it in iOS by having the server code open a TCP listener socket bound to 0.0.0.0; the client code can then construct a URL from this and talk to the server using NSURLConnection.
(Yes, this is a bit of a kludge. In the long run we could switch to using some other mechanism, but it would be a big architectural change since HTTP is pretty fundamental to the way CouchDB works.)
Problems this causes are
- When the listener socket re-opens it gets a different randomized port number, invalidating any URLs the client code is keeping around. (We can try to re-use the same port we got the first time, but that’s not guaranteed to succeed.)
- On returning to the foreground we have a race condition between client code that wants to start connections, and the server code that needs to re-open its listener. This needs some kind of synchronization to resolve.
- Any HTTP transactions still in flight get invalidated too and have to be re-started somehow. (Or else we track them all, and delay going into the background until they complete.)
We can solve these, but it would be so much easier if we could somehow keep that listener socket open.
—Jens _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden