我正在尝试使用Windows 10中的蓝牙连接到套接字。代码如下所示:
var services = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.FromUuid(new Guid("e2645167-6352-4429-b0db-45a36f424ebc"))));
if (services.Count > 0)
{
// Initialize the target Bluetooth BR device
var service = await RfcommDeviceService.FromIdAsync(services[0].Id);
// Check that the service meets this App's minimum requirement
if (SupportsProtection(service))
{
_service = service;
try
{
await _socket.ConnectAsync(_service.ConnectionHostName, _service.ConnectionServiceName);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
}
应用程序在ConnectAsync
方法中失败。异常消息仅显示The requested address is not valid in its context
。