Skip to content
This repository has been archived by the owner on Sep 19, 2019. It is now read-only.

Multiplayer P2P game connection problem #73

Closed
plabon opened this issue Nov 27, 2018 · 1 comment
Closed

Multiplayer P2P game connection problem #73

plabon opened this issue Nov 27, 2018 · 1 comment

Comments

@plabon
Copy link

plabon commented Nov 27, 2018

  1. Currently i am working on a multiplayer P2P game using nearby api. For that i am using P2P_star strategy. Players can invite and join. But unfortunately we don't have the option to select the host or client from the UI, so the whole topology creation should be autonomous. So is there any way to know from the api which device is the master after the creation of P2P_star. Because i need to know the master to propagate the game info to other devices. And please suggest me the way or good practices, nearby suggest to implement multiplayer p2p games.

  2. First every devices are Advertising and Discovering both and trying to find the pair. And when any end point found that request connection. I often getting onFailure callback with the following exceptions randomly: STATUS_BLUETOOTH_ERROR, STATUS_OUT_OF_ORDER_API_CALL, STATUS_ENDPOINT_IO_ERROR etc. Currently when i get onFailure callback i stop discovering and start again after sometimes(1000ms). I keep the advertising running(not stoping and starting).
    Am i doing this right or you have any other suggessions in my usecase?

@reznor
Copy link
Contributor

reznor commented Nov 27, 2018

P2P_STAR is meant for 1:N connection topologies, so it's going to be difficult (not impossible, but complicated, because you essentially need master-election) for you to build a self-assembling network using that -- that's because once an Advertiser establishes the first incoming connection, it cannot then make any outgoing connections (because it is now the "1" in the 1:N topology).

A better way to model this might be to have every Advertiser a random number as a part of its endpointName, with the rule that everyone will only connect to the Advertiser with the highest number it sees; that achieves a rudimentary master-election without a prior shared control plane, but you'll need some tweaks like letting all Discoverers discover for some fixed time (like 20 seconds) before ranking all the Advertisers it sees (to decide who the "host" of the group is). What I've mentioned is also not robust in the face of new phones leaving and joining the group, but there's clever ways you can work around that if you give it some thought. :)

Also, in the future, please post questions that are not related to the sample apps themselves on StackOverflow (tagged with https://stackoverflow.com/questions/tagged/google-nearby).

Good luck!

@reznor reznor closed this as completed Nov 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants