Windows.Networking.Proximity.WindowsUri
The WindowsUri class represents a Uniform Resource Identifier (URI) that can be used for Windows Runtime (WinRT) applications to communicate with other devices using Wi-Fi Direct. This allows for peer-to-peer connections and data transfer without the need for a network infrastructure.
Overview
Wi-Fi Direct enables devices to connect directly to each other using Wi-Fi. The WindowsUri class is a key component for initiating and managing these connections within UWP applications. It defines a standardized way to represent the target of a Wi-Fi Direct connection.
Key Concepts
- Peer-to-Peer Connectivity: Establish direct connections between devices.
- Discovery: Find other devices advertising Wi-Fi Direct services.
- Data Transfer: Send and receive data over the established connection.
- URI Representation: A standardized format for identifying Wi-Fi Direct endpoints.
Namespace
Windows.Networking.Proximity
Syntax
public sealed class WindowsUri
Properties
-
DisplayNamestring
Gets or sets a human-readable name for the Wi-Fi Direct service or device.
-
RawUristring
Gets the raw URI string for the Wi-Fi Direct endpoint.
Methods
-
WindowsUri(string uri)
Initializes a new instance of the WindowsUri class with the specified URI string.
public WindowsUri(string uri);
-
Equals(object obj)
Determines whether the specified object is equal to the current object.
-
GetHashCode()
Serves as the default hash function.
-
GetType()
Gets the Type of the current instance.
-
ToString()
Returns a string that represents the current object.
Usage Example
The following example demonstrates how to create a WindowsUri object and use it to initiate a Wi-Fi Direct connection.
Note:
This example assumes you have the necessary permissions and have implemented the peer discovery and connection logic using other Windows Runtime APIs like ProximityDevice and ConnectionRequestedEventArgs.
using Windows.Networking.Proximity; using Windows.Foundation; // ... inside an async method or event handler // Define the URI for a Wi-Fi Direct service (example) string serviceUriString = "ms-winsock:tcpip/192.168.1.100:8080"; try { // Create a WindowsUri object WindowsUri peerUri = new WindowsUri(serviceUriString); peerUri.DisplayName = "My File Transfer Service"; // Now you can use this peerUri object with ProximityDevice for connection // For instance, when handling a ConnectionRequested event: // e.ConnectionRequestedEventArgs.PeerFinderUri = peerUri; // Or when publishing a service (if applicable) // ProximityDevice.PublishUriMessage(peerUri); System.Diagnostics.Debug.WriteLine($"Successfully created WindowsUri for: {peerUri.RawUri}"); } catch (ArgumentException ex) { System.Diagnostics.Debug.WriteLine($"Error creating WindowsUri: {ex.Message}"); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine($"An unexpected error occurred: {ex.Message}"); }