Game Development Reference
In-Depth Information
The Async part of the FindAllPeersAsync() method indicates that this method
will run in the background and eventually return the information we asked for, so we
need to make use of the task system in WinRT to continue once the method com-
pletes.
Note
For more information on what Async is, refer to the Side note - Async section.
Once we retrieve the result, we have a list of peers available to work with. From there
we need to convey this to the players so that they can select who they want to con-
nect to. Meanwhile you need to store the PeerInformation objects stored in the
list so that you can make use of them later. If you need an identifier to convey which
connection is which to the players, you can use the DisplayName property, which
will show the name of the machine detected.
Now that you have a PeerInformation object to connect to, you can call the
PeerFinder::ConnectAsync() method, passing in the PeerInformation ob-
ject to establish the connection, as shown:
auto op = PeerFinder::ConnectAsync(peer);
concurrency::task<StreamSocket^>
connectTask(op);
connectTask.then(
[this](concurrency::task<StreamSocket^>
resultTask)
{
auto socket = resultTask.get();
// Use socket to communicate
});
Once we continue after connecting, we can retrieve the StreamSocket and begin
communicating.
Search WWH ::




Custom Search