I have an application that uses an API to get real time updates on the website. They use what they call a long-polling technique:
Long polling is a variation of the
traditional polling technique and
allows emulation of an information
push from a server to a client. With
long polling, the client requests
information from the server in a
similar way to a normal poll. However,
if the server does not have any
information available for the client,
instead of sending an empty response,
the server holds the request and waits
for some information to be available.
Once the information becomes available
(or after a suitable timeout), a
complete response is sent to the
client. The client will normally then
immediately re-request information
from the server, so that the server
will almost always have an available
waiting request that it can use to
deliver data in response to an event.
In a web/AJAX context, long polling is
also known as Comet programming.Long polling is itself not a push
technology, but can be used under
circumstances where a real push is not
possible.
Basically this enforces to make a request back to the server once you’ve got a response back. What is the best way to do this in an iphone application? This eventually has to run in the background.
This is exactly the sort of use-case that
NSURLConnection sendSynchronousRequestis perfect for:Alternately, you could use async I/O and delegate callbacks to accomplish the same thing, but that would really be kind of silly in this case.