Game Development Reference
In-Depth Information
PeerFinder::Start();
PeerFinder::ConnectionRequested += ref new
TypedEventHandler<Object^,
Windows::Networking::Proximity::ConnectionRequestedEventArgs^>(this,
&MyClass::HandleConnection);
To accept a connection we need to hook into the ConnectionRequested event,
which will provide us with a PeerInformation object describing the peer that
wants to connect. Using this we can call the ConnectAsync() method and accept
the connection, which will provide us with a StreamSocket just like when you con-
nect as a client. I'll describe how to work with this method in the following section.
The other scenario that PeerFinder supports is discovering and connecting to
peers (as opposed to just advertising). How you present this to the player is up to
you; however, by calling the PeerFinder::Start() method you begin advertising
your machine as a peer, and others may try to connect to you. As PeerFinder only
works when players are physically close to each other, you could safely implement
this system as a local lobby where all the players can see each other, and then at-
tempt to establish and accept each other's connections to start a game.
The first step to connect to someone else is to find the nearby peers, this is done
with the PeerFinder::FindAllPeersAsync() method, as shown:
using namespace concurrency;
PeerFinder::Start();
auto op = PeerFinder::FindAllPeersAsync();
task<IVectorView<PeerInformation^>^>
findAllPeersTask(op);
findAllPeersTask.then(
[this]
(concurrency::task<IVectorView<PeerInformation^>^>
resultTask)
{
auto peerList = resultTask.get();
});
Search WWH ::




Custom Search