views:

47

answers:

2

I am building an app which allows a user to draw on the screen. I'd like to add network capability so that user A can draw on user B's screen. My current plan is to build a system where I have my own UserOrNetworkTouch object which can be created based on either a real UITouch, or a message which comes over the network, and base all of the drawing in the app off of UserOrNetworkTouch events, rather than UITouch events.

Another thing I'll want to use this system for is recording touches, so a user will be able to press "record", and then play back their drawing at a later time.

I'd like to make sure I'm not reinventing the wheel here. Are there any libraries available which will handle some or all of this for me?

+3  A: 

You probably wouldn't send the UITouch objects over the network (although you could if you wanted). I might package then touch positions into a struct of some kind and just send that to decrease the amount of traffic you were sending. If you needed the entire UITouch object and all of its data then sure, send the object to your server.

You could use CFNetwork framework to send data to a server from your client application. If you do you should really try to use IPv6.

Apple have sample code here for working with CFNetwork streams

If you want to record the touch events, just use an NSArray or an NSDictionary if you wanted to store say the touch along with a timestamp for when the touch occurred.

Then just add each touch to the array or dictionary as the user makes them.

Update: I wouldn't waste your time with Apple's WiTap sample code. I've read though it before and there is a LOT of code in it that is just confusing and irrelevant if you want a simple client/server app up and running quickly. It will more than likely be way too confusing for you if you haven't done any network programming before.

I would get the network transfers working first, then if you like you can refer to WiTap for the Bonjour networking part so you can do auto discovery of the client and server. But add Bonjour support only after you have data steams working first.

Brock Woolf
Bonjour isn't hard, and you can skip CFNetwork and get straight to using NSStreams. WiTap's code is mostly Bonjour, and offers a table view showing devices serving up what your app needs.Apple has another excellent sample, just updated, 'PictureSharing'. While it's Mac-based, the code runs on iPhone just fine. It uses Bonjour to connect and has some helpful run loop/NSOperation classes; in their case to send files, but you could use them to send anything.
Graham Perks
A: 

A good place to start would be Apple's WiTap sample. It sets up a game over Bonjour and sends taps back and forth.

Also look at GameKit which'll make some of the networking even simpler.

A SQLite DB would be a great place to record events. Search for the 'fmdb' SQLite wrapper for a nice Objective-C wrapper.

Graham Perks