views:

47

answers:

2

I am currently trying to build a (simplified) stock app (like the one built-in on the iphone). I setup a simple server with a REST-interface which my app can communicate with.

However I am struggling to find the right/best way to build this kind of (streaming data consumer) client on the iphone.

My best bet at the moment is to use a timer to regularly pull the xml payload from the server (the connection is async but the xml parsing is not therefor the interface is blocked sometimes. I am a bit shy of thread programming since I learned some lessons the hard way on other platforms).

I read about websockets but it is not clear for me if and how they are supported on the iphone.

How would you do it?

Any hint would be appreciated, Thanks.

A: 

websockets aren't going to help you -- that's a server-side technology to make a socket-like interface work over HTTP.

If you don't want to block the GUI, you need to use another thread. You are right to be scared of doing this, so share as little as possible (preferably nothing) between the two threads. Use a message passing mechanism to get information from the background thread to the UI thread.

Take a look at ActorKit: http://landonf.bikemonkey.org/code/iphone/ActorKit_Async_Messaging.20081203.html

Lou Franco
So, basically, polling data inside a timer (within a background thread) is the way to go? Any thoughts on other push technologies (although I dont really want to mess around with proprietary xmpp servers ...)
michasvision
This has more to do with how many customers you think you'll have simultaneously and how much server power you can put behind it. Also, how often the data changes and how much latency is acceptable. Polling is fine if some latency is ok, and you want to lower stress on servers. On the client, if you want to not block the GUI, you need to use a background thread.
Lou Franco
A: 

Take a look at this question.

It talks about asynchronous vs synchronous connections. You will want to use an asynchronous call to get your data so you don't lock up your UI. You could use that in conjunction with a polling timer to get your data from the server.

You can find more info about the NSURLConnection in apple's documentation here

Geoff Baum