2

I am developing an iPhone application that allows to basically click through a series of actions. These series are predefined and synced with a common configuration server.

That app might be running on multiple devices at the same time. All devices are assumed to have the same series of actions defined on them. All devices are considered equal, there is not a server and multiple clients or something like that.

(Only) one of these devices is used by a person at any given time, it is however possible that the person switches to a different device at any given time. All "passive" devices need to be synchronized with the active one, so that they display the same action.

The whole thing should happen as automatically as possible. No selection of devices, configuration, all devices in the same network take part in the same series of actions.

One additional requirement is that a device could join during a presentation (a series of actions) and needs to jump to the currently active action.

Right now, I see two options to implement the networking/communication part of that:

  • Bonjour. I have implemented a working prototype that can automatically connect with one (1) other device in the network and communicate with that. I am not sure at this point how much additional work the "multiple devices" requirement is. Would I have to open a set of connections for every device and manually send the sync events to all of them? Is there a better way or does bonjour provide anything to help me with that? What does Bonjour provide given that I want to communicate with every device in the network anyway?

  • Multicast with AsyncUdpSocket. Simply define a port and send multicast sync events out to that port. I guess the main issue compared to using bonjour with tcp would be that the connection is not safe and packets could be lost. This is however in a private, protected wlan network with low traffic if that would really be an issue. Are there other disadvantages that I'm not seeing? Because that sounds like a relatively easy option at this point...

Which one would you suggest? Or is there another, better alternative that I'm not thinking of?

Berdir
  • 6,881
  • 2
  • 26
  • 38

3 Answers3

2

You should check out GameKit (built in to iOS)--they have a lot of the machinery you need in a convenient package. You can easily discover peers on the network and easily send data back for forth between clients (broadcast or peer to peer)

nielsbot
  • 15,922
  • 4
  • 48
  • 73
  • Thanks. I've been reading through http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/GameKit_Guide/GameKitConcepts/GameKitConcepts.html and I'm not sure what is the best way to make this as configuration/setup-free as possible. Specifically, I'd like to avoid that someone needs to start a server so that others can connect to it. So one idea is to look for a server first for a few seconds and if there is none, start a new one. Sounds good? – Berdir May 16 '11 at 19:11
  • I don't think you need to wait a few seconds. I think you should create a negotiation protocol where the devices decide among themselves who will be the server. (For example, the first device to arrive could be the server) – nielsbot May 16 '11 at 19:15
  • The real problem will be when a device walks out of the room or drops off the network, if that will be possible with your scenario. There's no way for a device that leaves the network to announce "hey I'm leaving"--so the other devices will have to just notice and then elect a new server device. If your protocol doesn't depend on responsiveness around this scenario you'll be fine, however. – nielsbot May 16 '11 at 19:17
  • Thanks, I'll see where that leads me and report back. Certainly sounds interesting. Good point about loosing connectivity, I don't think I need to cover that case, however. – Berdir May 16 '11 at 19:23
  • good luck.aside: i used to work on firewire and they have a system where a node on the bus is voted "bus master". sounds similar. In the firewire case however you always know when a device appears/disappears since it involves plugging something in... – nielsbot May 16 '11 at 20:03
1

In my experience Bonjour is perfect for what you want. There's an excellent tutorial with associated source code: Chatty that can be easily modified to suit your purposes.

elibud
  • 8,119
  • 2
  • 21
  • 21
0

I hobbled together a distributed message bus for the iphone (no centralized server) that would work great for this. It should be noted that the UI guy made a mess of the code, so thar' be dragons there: https://code.google.com/p/iphonebusmiddleware/

The basic idea is to use bonjour to form a network with leader election. The leader becomes the hub through which all the slaves subscribe to topics of interest. Then any message sent to a given topic is delivered to every node subscribed to said topic. A master disconnection simple means restarting the leader election process.

Bashwork
  • 1,619
  • 8
  • 14