连接到BluetoothSocket时,请求的地址在其上下文中无效

时间:2016-05-31 16:59:44

标签: c# bluetooth windows-10 uwp

我正在尝试使用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

0 个答案:

没有答案