Windows.Devices.WiFiDirect.Services Namespace
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Provides support for implementing your own Wi-Fi Direct Services.
Wi-Fi Direct is a technology that enables two devices to connect directly to each other using Wi-Fi, without needing to join an existing network through an access point. Wi-Fi Direct Services are the way that one device (a Service Advertiser) offers capabilities to another device (a Service Seeker) over a Wi-Fi Direct connection. A seeker makes use of an advertised service by establishing a session. A given device can advertise multiple services and also seek multiple services. The Seeker and Advertiser roles are defined with respect to how the devices interact in a particular session.
While the Wi-Fi Direct Services specification defines several standard services, this API supports only the Enable service. It does not support Send, Play, Print, or Display functionality.
Classes
WiFiDirectService |
Represents a Wi-Fi Direct service. This class is used by code on a device that seeks to use a Wi-Fi Direct Service, to establish a Wi-Fi Direct Service session with the service provider. |
WiFiDirectServiceAdvertiser |
Represents a Service Advertiser. This class is used by code on a device that advertises Wi-Fi Direct Services, to advertise the service. |
WiFiDirectServiceAutoAcceptSessionConnectedEventArgs |
Returned when a WiFiDirectServiceAdvertiser.AutoAcceptSessionConnected event is raised. |
WiFiDirectServiceProvisioningInfo |
Contains provisioning information about a Wi-Fi Direct Service. |
WiFiDirectServiceRemotePortAddedEventArgs |
Returned when a WiFiDirectServiceSession.RemotePortAdded event is raised. Your event handler should use this information to establish new socket connections to the new port. |
WiFiDirectServiceSession |
Represents a Wi-Fi Direct Services (WFDS) session. |
WiFiDirectServiceSessionDeferredEventArgs |
Returned when a WiFiDirectService.SessionDeferred event is raised. |
WiFiDirectServiceSessionRequest |
Describes a Wi-Fi Direct Service session request. |
WiFiDirectServiceSessionRequestedEventArgs |
Returned when a WiFiDirectServiceAdvertiser.SessionRequested event is raised. |
Enums
WiFiDirectServiceAdvertisementStatus |
Values used for WiFiDirectServiceAdvertiser.AdvertisementStatus. |
WiFiDirectServiceConfigurationMethod |
Values describing how service configuration is performed when a session is being established. Typically, either no input is required, or one device in the session displays a PIN and the other device requires that the PIN be entered. |
WiFiDirectServiceError |
Values used for the WiFiDirectServiceAdvertiser.ServiceError property. |
WiFiDirectServiceIPProtocol |
Defines constants that specify the IP protocol of the new port when a WiFiDirectServiceSession.RemotePortAdded event is raised. |
WiFiDirectServiceSessionErrorStatus |
Values used in the WiFiDirectServiceSession.ErrorStatus property. |
WiFiDirectServiceSessionStatus |
Values used to describe the status of a Wi-Fi Direct Service Session. |
WiFiDirectServiceStatus |
Values used to describe the service status. |
Remarks
Setting the Group Owner (GO)
You might want to be able to exert precise control over which of the members of a Peer to Peer (P2P) group is the Group Owner (GO). Your code should use the WiFiDirectAdvertiser.PreferGroupOwnerMode property to specify that a given advertiser wants to be the GO. However, if two devices have been previously paired via Wi-Fi Direct, then the Wi-Fi direct roles in the saved profile from that pairing override the advertiser's specified preference. In order to guarantee that a given device in a P2P pairing will be the GO, you must first delete any existing pairing data, using methods provided by the Windows.Devices.Enumeration namespace.
Note that a pairing profile pairs two MAC addresses, so unpairing two devices applies to all apps that use Wi-Fi Direct between those two devices. Your app should never assume that a pairing profile exists, or that it has not been changed by another app, even if it has paired with a device in the past. You should get current profile information from the current profile rather than storing profile information and assuming it is still true at a later date. Another app might have changed the pairing profile in the interim.
The following code finds any Wi-Fi Direct pairing profile between the local device and another device, and unpairs the two devices. After this code has successfully unpaired the two devices, subsequent pairing will obey the WiFiDirectAdvertiser.PreferGroupOwnerMode value active at the time of pairing.
using Windows.Devices.Enumeration;
private async void Unpair_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
if (DiscoveredServices.Items.Count > 0)
{
DiscoveredDeviceWrapper service =
(DiscoveredDeviceWrapper)DiscoveredServices.Items[DiscoveredServices.SelectedIndex];
String[] aepId = service.DeviceInfo.Id.Split('#');
String deviceSelector = "System.Devices.DeviceInstanceId:=\"SWD\\WiFiDirect\\" + aepId[1] + "\"";
// Check if device is paired
DeviceInformationCollection pairedDeviceCollection =
await DeviceInformation.FindAllAsync(deviceSelector, null, DeviceInformationKind.DeviceInterface);
if (pairedDeviceCollection.Count > 0)
{
try
{
DeviceInformation devInfo = pairedDeviceCollection[0];
await devInfo.Pairing.UnpairAsync();
MainPage.Current.NotifyUser("UnpairAsync succeeded", NotifyType.StatusMessage);
}
catch (Exception ex)
{
MainPage.Current.NotifyUser("UnpairAsync failed: " + ex.Message, NotifyType.ErrorMessage);
}
}
}
}