7

I have just delivered a prototype for a big client, everything was fine but I'm now curious to know if the solution/architecture I've chosen was the right one or there's place for improvement in case the project will keep on.

The task was to build two iOS apps: one running on 5 different iPhones, and another running on 2 iPads. Basically the iPhone applications had to communicate information to the iPads, and occasionally they also had to send information between each other (iPhone to iPhone). All the infos where small JSON objects/chunks whose size was small, really small.

The app was not intended to reach the app store, is a working prototype to test out some ideas in a user testing environment.

I discarded bluetooth because we are talking about a peer-to-peer communication, not a one-to-one.

What I did was to use web sockets thanks to SocketIO, through a small Node.js server that was running on my mac. The server was really simple, just receiving the messages from the clients and broadcasting information to the other ones.

What do you think? Is the solution I've chosen ok, or there are better ones?

For example, this morning I've just found out these thread here on SO, and I've discovered I could have used GameKit. What do you think?

jscs
  • 63,694
  • 13
  • 151
  • 195
Sr.Richie
  • 5,680
  • 5
  • 38
  • 62
  • Deploying onto the app store? Bluetooth a possibility for you? Lan will always be available? What size of data is being transferred? We really don't know enough. Your solution sounds ok, it works and it should be extensible. – Wain Jun 17 '14 at 09:33
  • thx @Wain, I've edited the question with the relevant info – Sr.Richie Jun 17 '14 at 10:00

4 Answers4

3

Socket.IO is nice because it is fairly simple to implement but it has the downside of requiring a central server. If you wanted to avoid that, you could use the Multipeer Connectivity framework that was introduced in iOS 7.

It will let you create one-to-one communication channels between devices on either the same WiFi network or Bluetooth. Once the channel is created, you can send whole NSData objects (or create streams but it doesn't seem relevant to your use case).

A good read : http://nshipster.com/multipeer-connectivity/

Taum
  • 2,511
  • 18
  • 18
2

The WiTap sample from Apple demonstrates peer-to-peer networking over Wi-Fi and Bluetooth. Using Bonjour, the application both advertises itself on the local network and displays a list of other instances on the network. Supports infrastructure networks, peer-to-peer Bluetooth, and peer-to-peer Wi-Fi (on compatible hardware).

I have personally tested it and it works fine and well documented.

Gokila Dorai
  • 100
  • 5
1

I think socket.io is the best choice. It is built on top of engine.io (which in turn is built on the fastest websocket implementation: ws) It has oldest to newest fallbacks, so it starts with long polling and works its way up. This guarantees a quick initial connection instead of needing to poll the device for features. You can read more on this here. Best of all, it handles everything seamlessly. You write your code as if websockets are supported on connecting devices and if not it will use other methods behind the scenes.

This post details many of the websocket libraries you could use with your server. Which websocket library to use with Node.js?

Community
  • 1
  • 1
Spencer
  • 1,527
  • 1
  • 10
  • 23
0

I am convinced Bonjour is the best solution:

Apps can also leverage Bonjour to automatically detect other instances of the app (or other services) on the network.

However I've never used it myself; perhaps someone who has can comment?

trojanfoe
  • 120,358
  • 21
  • 212
  • 242
  • 4
    You are convinced it is the best choice but you have never used it? Really? – Spencer Jun 17 '14 at 14:15
  • 1
    Bonjour is only for discovery though, after that you need to roll your own messaging protocol. – Taum Jun 17 '14 at 14:19
  • That's OK. For me it's the discovery that is the key benefit. For the actual comms then CocoaAsyncSocket would be a good choice. – trojanfoe Jun 17 '14 at 14:20
  • I am as well. Here is an example of an app that does this: https://github.com/brendaninnis/LocalNetworkingApp – InnisBrendan Nov 17 '19 at 01:28