I hope to use the Multipeer Connectivity framework, and would appreciate any voices of experience on how best to proceed.
I need a connection between a "coach" device and up to 45 "player" devices. They will all be in the same space, but no way to predict wifi availability or connection. The coach device needs to send an instruction (a small data packet) to all player devices each second. Each "player" needs to send a reading from a Bluetooth Heartrate monitor (very small data packet) back to the coach each second. Since the maximum peers per session is 8, would any of these ideas work to accommodate the numbers I need?
a) The first 7 player devices to establish a connection with the coach advertise a different session type and allow 7 (or would this be 6?) more players to join them. Those first 7 act as a middleman to the other 49 (or 42?) by passing on the instruction from the coach and passing back the collected readings to the coach. A few second lag between instruction and heartrate reading is not preferred, but would be OK.
b) The coach device creates and advertises one session. After 7 player devices have connected, the coach device creates another session and repeats for 7 more. Repeat until all player devices are connected to the coach. This seems unlikely to work, but without understanding the magic that is Multipeer Connectivity, it was an option that came to mind.
c) The coach establishes a session with player device one, which connects to device 2... in a daisy chain topography. When each device recieves the instruction, it adds it's own reading to the data packet and sends it on. The last device returns the entire packet to the coach. I can't predict how long it would take for a round of data, and it also seems troublesome if one device leaves the group.
Any advice or voices of experience in using Multipeer Connection Framework for 45 or so devices would be appreciated.
I've been pondering something similar lately, and I'd say in your case b) would be your best option if you don't need the 'players' to communicate with each other.
Multipeer Connectivity supports multiple sessions so you could have an array for session objects, advertise as the 'coach' and with each discovered player either invite to the latest session if it has capacity or create a new one.
Your player object can keep a reference to the session and peerID for the purposes of sending data, and maybe keep a dictionary of peerID displayNames mapped to the corresponding player object to handle incoming data.
This way you also have no hops between a given 'player' and the 'coach', unlike with a) and c).
Obviously the real trick here is testing. I myself don't own 8+ devices and I'm still not sure how I'm going to test my own implementation!
Edit
I answered a similar question with actual code here: Best option for streaming data between iPhones
I Know that it is an old question. I had the same problem mounts ago (and have asked a similar question without clear answer).
Things that I have tested and problems faced:
The "normal way" -- one session.
- Problem: Maximum 8 devices.
Array of sessions putting 6 devices on each session (to avoid the maximum 8)
- Problem: To much overheating, memory and cpu consumption. When several devices from several session get disconnected at a time the reconection can take to much time to be aceptable.
This is the most complicated way.
Steps:
- We create the session and allow a maximum of 4 - 5 clients.
- Every time a client is connected he create a group with the same conditions.
- When We reach the maximum client count (4 - 5 depending on your implementation ) we stop advertising.
- New clients will be connected between each other like cells. The trick is to have some method to decide witch sessions the new client needs to connect to ordered by priority and create a method to resent traffic to the client session to the "server replicator" one.
The only problem with the last method is that it is the most complicated and you need some maths a pencil and a peace of paper to decide how you will interconect your clients and resend your traffic.
Instead of MultiPeer Connectivity framework, You can go with this https://github.com/jdiehl/async-network#request-based-networking
the default is 8, it's not the maximum,
you question scared me, as I will need more than 8 too!!
it must of been poorly written looks corrected below.
maximumNumberOfPeers The maximum number of peers allowed in a session, including the local peer. @property(assign, nonatomic) NSUInteger maximumNumberOfPeers Discussion The largest allowable value (and the default) is 8.
来源:https://stackoverflow.com/questions/19479295/multipeer-connectivity-framework-for-up-to-45-devices