Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multipeer connectivity framework: Stability and Recommendations

I'm working on a project that uses MC framework as a communication channel, and after some tests I have the perception that this channel is somehow unstable to rely on.

I've been following Apple's documentations and videos in order to use the framework properly, but happens that:

  • peers get disconnected kinda' often after paired, and even more ofter if I pair more than one peer.
  • some data packages have mixed data

Is there any kind of recommendation to work with the framework? i.e:

  • Specific project settings? (i.e: is there something in the capabilities section that needs to be enabled?)
  • Multithreading restrictions? (i.e: always call mc methods from the same thread)
  • Restrictions in terms of the amount of data to be sent?

I found this link that mentions something about the framework not performing ok under stress. That's the kind of advice I'm looking for :).

For the record:

  • I'm using an implementation based on this post since Apple's project is not working for me.
  • I'm using only one MCSession for all peers I try to pair with
  • Encryption preference is set to MCEncryptionNone
  • Using sendData: and sendResourceAtURL: to communicate with peers.
like image 832
Omer Avatar asked Jan 04 '16 18:01

Omer


People also ask

What is Multipeer connectivity?

The Multipeer Connectivity framework supports the discovery of services provided by nearby devices and supports communicating with those services through message-based data, streaming data, and resources (such as files).

What is peer to peer on Iphone?

Here, the app uses Apple's Multipeer Connectivity framework, essentially a peer-to-peer feature that lets you share messages (and soon photos) with other app users nearby, regardless of whether you have an actual Wi-Fi or cellular connection.


1 Answers

I'm using the MC framework in a game and have found a few workarounds for its apparent instability:

1) I use a "keep alive" transaction sent every 15 seconds to maintain activity on the links. I found that this resolves almost all the connection losses I was experiencing.

2) I dispatch all processing triggered by data reception to the main thread and never carry any MCPeer nor MCSession objects between threads (except for the initial connection protocol). I also did that to minimize the time spent in the data reception code so that the thread used by MC regains control as fast as possible (which I also found was a source of some disconnects). I do not apply this rule for sending data (only when receiving)

3) I have NOT found a clean solution to the repetition of peers that appears when trying to establish a connection (both using the standard UI and my own). So far comparing MCPeer IDs to avoid duplicates only seems to remove some of the duplication. Also, it seemed that using the same MCSession for advertising (MCAdvertiserAssistant) and connecting to peers caused some conflicts so i'm using a new, separate MCSession instance every time I start the assistant.

like image 66
Alain T. Avatar answered Oct 05 '22 12:10

Alain T.