Avoid iPhone constant polling a web
I have an iPhone application that needs to be updated as soon as a change is made to the server. How can I have the server "push" data to the iphone rather than the iphone constantly polling the web service?
EDIT: I want th iPhone to receive JSON updates as soon as the server processes them, without having to request.
I suppose since the server is a web service that this is called Comet, but I haven't seen a good iPhone example yet.
That depends on how adventurous you are. There are two alternatives here:
UPDATE: Take a look at iStreamLight - Lightstreamer protocol implementation for iPhone. If it doesn't fit your Comet web-service, you probably need to go down to the lower level, which is maintaining TCP connection using socket streams. To simplify your task in handling JSON data structures, you might want to use JSON framework for Objective-C.
What you need is some sort of COMET framework (such as light-streamer). There are a several ways to do that - socket connections or HTTP server that hold onto your polls until there is some data available to deliver or until the HTTP request times out. Other options include using plug-ins such like Flash or Silverlight/Moonlight (assuming such a thing were possible on the iphone using monotouch?)
A good new (IIS based) COMET framework that can move a lot of data in a very performant way is WebSync from Frozen Mountain, that supports a hosted COMET based PubSub framework (called WebSync on Demand) that can scale to suit your load. It works nicely via Javascript, and has a pretty clean API.
This may have been mentioned in the other post, but http://code.google.com/p/istreamlight/ is a good place to check out. It uses the lightstreamer server (don't know about it.) You might take a look to see if this is how you would like to implement a comet client for your application.
I honestly wish I could be more helpful. If you were asking for a way to do this in javascript, I'd be all over it!
Good luck,
-Todd
链接地址: http://www.djcxy.com/p/12920.html上一篇: 使用Java轮询Web服务
下一篇: 避免iPhone不断轮询网页