แก้ไข

แชร์ผ่าน


PeerCollaboration.GetPeersNearMe Method

Definition

Returns a collection of all the PeerCollaboration endpoints currently signed in on the network subnet of the calling peer.

public:
 static System::Net::PeerToPeer::Collaboration::PeerNearMeCollection ^ GetPeersNearMe();
[System.Security.SecurityCritical]
public static System.Net.PeerToPeer.Collaboration.PeerNearMeCollection GetPeersNearMe ();
[<System.Security.SecurityCritical>]
static member GetPeersNearMe : unit -> System.Net.PeerToPeer.Collaboration.PeerNearMeCollection
Public Shared Function GetPeersNearMe () As PeerNearMeCollection

Returns

A PeerNearMeCollection that contains all the PeerCollaboration endpoints currently signed into the 'Near Me' scope.

If peers are not discovered on the subnet, a collection of size zero (0) is returned.

Attributes

Exceptions

The peer is not signed in to the 'Near Me' scope.

An invalid value was returned when this method attempted to enumerate all known People Near Me endpoints.

Examples

The following code example illustrates how to retrieve PeersNearMe as a PeerNearMeCollection:

//This function retrieves the peers near me as a PeerNearMeCollection.
public static PeerNearMeCollection GetPeersNearMe()
{
    PeerNearMeCollection peers = null;
    try
    {
        peers = PeerCollaboration.GetPeersNearMe();
        if (peers == null ||
            peers.Count == 0)
        {
            Console.WriteLine("There are no peers near me.");
        }
        foreach (PeerNearMe pnm in peers)
        {
            Console.WriteLine("Getting the peers near me: {0}, nickname {1}, isOnline {2}",
                pnm.ToString(),
                pnm.Nickname,
                pnm.IsOnline);
        }
    }
    catch (PeerToPeerException p2pEx)
    {
        Console.WriteLine("Could not obtain an enumeration of the peers near me: {0}", p2pEx.Message);
    }
    catch (InvalidOperationException ioEx)
    {
        Console.WriteLine("The application is no longer signed into the Peer Collaboration Infrastructure: {0}",
            ioEx.Message);
    }
    catch (Exception ex)
    {
        Console.WriteLine("Unexpected exception caught when trying to enumerate the peers near me: {0}",
            ex.Message);
    }

    return peers;
}

Remarks

The return of a fully populated PeerNearMeCollection via this method can require an indeterminate amount of time after sign-in depending on network topology and latency.

Calling this method requires a PermissionState of Unrestricted. This state is created when the Peer collaboration session begins.

Applies to