Search code examples
iphonenetwork-programmingsynchronizationbonjourmultiple-instances

How to sync an application state over multiple iphones in the same network?


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?


Solution

  • 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)