如何在同一网络中的多部 iPhone 上同步应用程序状态?

发布于 2024-11-04 11:05:00 字数 783 浏览 0 评论 0原文

我正在开发一个 iPhone 应用程序,基本上可以通过单击来执行一系列操作。这些系列是预定义的并与通用配置服务器同步。

该应用程序可能同时在多个设备上运行。假定所有设备都定义了相同的一系列操作。所有设备都被认为是平等的,不存在服务器和多个客户端或类似的东西。

(仅)一个人在任何给定时间使用这些设备中的一个,但是该人有可能在任何给定时间切换到不同的设备。所有“被动”设备都需要与主动设备同步,以便它们显示相同的操作。

整个事情应该尽可能自动发生。无需选择设备、配置,同一网络中的所有设备都参与同一系列的操作。

另一个要求是设备可以在演示(一系列操作)期间加入,并且需要跳转到当前活动的操作。

现在,我看到两个选项来实现其中的网络/通信部分:

  • Bonjour。我已经实现了一个工作原型,它可以自动与网络中的一(1)个其他设备连接并与之通信。我目前不确定“多个设备”要求需要多少额外工作。我是否必须为每个设备打开一组连接并手动将同步事件发送到所有设备?有没有更好的方法或者 bonjour 提供什么来帮助我吗?如果我想与网络中的每台设备进行通信,Bonjour 可以提供什么?

  • 使用 AsyncUdpSocket 进行多播。只需定义一个端口并将多播同步事件发送到该端口即可。我想与使用 bonjour 和 tcp 相比,主要问题是连接不安全并且数据包可能丢失。然而,如果这确实是一个问题,那么这是在一个低流量的私有、受保护的 WLAN 网络中。还有其他我没有看到的缺点吗?因为这听起来是一个相对简单的选择...

您会建议哪一个?或者还有其他我没有想到的更好的选择吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

抚你发端 2024-11-11 11:05:00

您应该查看 GameKit(内置于 iOS)——它们在一个方便的包中提供了您需要的许多机制。您可以轻松发现网络上的对等点,并轻松地在客户端之间来回发送数据(广播或点对点)

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)

寂寞花火° 2024-11-11 11:05:00

根据我的经验,Bonjour 非常适合您的需求。有一个带有相关源代码的优秀教程:Chatty,可以轻松使用修改以适合您的目的。

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.

〃温暖了心ぐ 2024-11-11 11:05:00

我为 iPhone(没有集中式服务器)搭建了一个分布式消息总线,这非常适合这个任务。应该指出的是,UI 人员把代码搞得一团糟,所以那里有龙:https: //code.google.com/p/iphonebusmiddleware/

基本思想是使用bonjour形成一个具有领导者选举的网络。领导者成为所有奴隶订阅感兴趣主题的中心。然后,发送到给定主题的任何消息都会被传递到订阅该主题的每个节点。主节点断开简单意味着重新启动领导者选举过程。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文