EN
Este conteúdo não está disponível em seu idioma, mas aqui está a versão em inglês.

Windows.Devices.WiFiDirect namespace

Applies to Windows and Windows Phone

Contains classes that support connecting to associated Wi-Fi Direct devices.

Members

The Windows.Devices.WiFiDirect namespace has these types of members:

Classes

The Windows.Devices.WiFiDirect namespace has these classes.

ClassDescription
WiFiDirectDevice Manages connections to associated Wi-Fi Direct devices.

 

Enumerations

The Windows.Devices.WiFiDirect namespace has these enumerations.

EnumerationDescription
WiFiDirectConnectionStatus Describes the connection status of a WiFiDirectDevice object.

 

Remarks

You can use the WiFiDirectDevice class to establish a socket connection with other devices that have a Wi-Fi Direct (WFD) capable device. You can call the GetDeviceSelector method to get the device identifier for a Wi-Fi Direct device. Once you have a reference to a WiFiDirectDevice on your computer, you can call the GetConnectionEndpointPairs method to get an EndpointPair object and establish a socket connection using the Windows.Networking.Sockets API.

You can add a handler for the ConnectionStatusChanged event to be notified when the connection has been established or disconnected.

Only one app can be connected to a Wi-Fi Direct device at a time.

You must enable the Proximity capability to communicate with Wi-Fi Direct devices.

Examples


var wfdDevice;

function connect(deviceId) {
    var result = ""; 

    try
    {
        // No device Id specified.
        if (!deviceId) { return "Please specify a Wi- Fi Direct device Id."; }

        // Connect to the selected Wi-Fi Direct device.
        Windows.Devices.WiFiDirect.WiFiDirectDevice.fromIdAsync(deviceId).then(
            function (wfdDeviceResult) {
                if (!wfdDeviceResult) {
                    result = "Connection to " + deviceId + " failed.";
                }

                wfdDevice = wfdDeviceResult;

                // Register for connection status change notification.
                wfdDevice.onconnectionstatuschanged = onConnectionChanged; 

                // Get the EndpointPair information.
                var endpointPairCollection = wfdDevice.getConnectionEndpointPairs();

                if (endpointPairCollection.Count > 0) {
                    var endpointPair = endpointPairCollection[0];
                    result = "Local IP address " + endpointPair.localHostName.toString() + 
                        " connected to remote IP address " + endpointPair.remoteHostName.toString();
                }
                else {
                    result = "Connection to " + deviceId + " failed.";
                }
            });

    }
    catch (err) {
        // Handle error.
        result = "Error occurred: " + err.message;
    }

    return result;
}

function onConnectionChanged(status) {
    if (status == Windows.Devices.WiFiDirect.WiFiDirectConnectionStatus.connected) {
        // Connection successful.
    }
    else {
        // Disconnected.
       disconnect();
    }
}

function disconnect() {
    if (wfdDevice) {
        wfdDevice.dispose(); 
    }
}


Requirements

Minimum supported client

Windows 8.1

Minimum supported server

Windows Server 2012 R2

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

Namespace

Windows.Devices.WiFiDirect
Windows::Devices::WiFiDirect [C++]

Metadata

Windows.winmd

See also

Samples
WiFiDirectDevice sample

 

 

Mostrar:
© 2014 Microsoft