Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection successful only 10% of the time #16

Open
sudeepag opened this issue Dec 20, 2015 · 12 comments
Open

Connection successful only 10% of the time #16

sudeepag opened this issue Dec 20, 2015 · 12 comments

Comments

@sudeepag
Copy link

I have set up PeerKit as per the example from the Cards Against app and have managed to get two devices to connect to each other.

However, this connection is only successful ~10% of the time. The other times, .onDisconnect is called right away. Is there any reason why this is happening, or am I doing something wrong?

Also, what is the procedure to attempt a reconnection after the connection is unsuccessful? Should I call .transceive again after creating a new Transceiver?

@sudeepag sudeepag changed the title .onConnect called only 10% of the time .onConnect called only 10% of the time Dec 20, 2015
@sudeepag sudeepag changed the title .onConnect called only 10% of the time Connection successful only 10% of the time Dec 20, 2015
@danshev
Copy link

danshev commented Jan 13, 2016

Also seeing this behavior -- any updates?

@jpsim
Copy link
Owner

jpsim commented Jan 13, 2016

Can you confirm that the problem is with PeerKit rather than Multipeer Connectivity? MPC itself isn't necessarily a paragon of reliability.

@danshev
Copy link

danshev commented Jan 13, 2016

Fair point; will investigate MPC directly.

Any guidance on @sudeepag 's question:

"Also, what is the procedure to attempt a reconnection after the connection is unsuccessful? Should I call .transceive again after creating a new Transceiver?"

@jpsim
Copy link
Owner

jpsim commented Jan 13, 2016

I'm not sure, I haven't touched PeerKit in a while.

@dkun7944
Copy link

dkun7944 commented Sep 7, 2016

@danshev Any progress on this? I'm noticing the same issue with my own app, though I used the ConnectionManager struct from Cards Against.

@danshev
Copy link

danshev commented Sep 7, 2016

@dkun7944 unfortunately, I concluded it was the general unreliability of the MPC framework.

@pdyakov
Copy link

pdyakov commented Sep 29, 2016

I found that problem is in Advertiser class in didReceiveInvitationFromPeer handler:
let accept = mcSession.myPeerID.hashValue > peerID.hashValue
Most of the time it resolves to "false" which lead to disconnection. If I change it to "true" peers connecting successfully all the time.
@jpsim can you please review this line? Why current peerID hash should be greater then external peerID hash for accepting connection?

@ashtonmeuser
Copy link

👍

@stevenbedrick
Copy link

I ran into similar problems, and eventually traced it back to the same place that @pdyakov did... my guess is that this test might be here to prevent an Advertiser from accepting an invitation from a Browser that was running on the same device (as in the case of transceiving)? If so, it should probably be comparing the hashValue of myPeerID/peerID's displayName properties. I've made that change in my local version of PeerKit, and it seems to be helping quite a lot, but am not confident enough in my understanding of the issue to submit a pull request. @jpsim, I'd be happy to do so if my reasoning is correct.

stevenbedrick added a commit to stevenbedrick/PeerKit that referenced this issue Feb 14, 2017
@qiulang
Copy link

qiulang commented Feb 24, 2017

I believe this is to fix a problem in iOS7 https://developer.apple.com/library/content/qa/qa1869/_index.html

If you don't need to support iOS 7 you can just accept invitation.

@stevenbedrick
Copy link

That certainly does appear to be the explanation, thanks, @qiulang!

@qiulang
Copy link

qiulang commented Feb 27, 2017

I think the main problem with current implementation is when peers first connected then disconnected, they won't connect again. Because when after they accept the invitation, advertiser.stopAdvertising(). So I added a state property in Session and re-start advertising when disconnect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants