2

我正在尝试使用 32feet.NET 作为客户端与蓝牙设备进行通信。该设备实际上是一个带有蓝牙模块的微控制器,但目前我正在使用我的 windows phone 进行测试。这些设备已经配对,这就是我所做的。(devinfo是所选设备的DeviceInfo)

private void ClientConnect()
{
    var client = new BluetoothClient();
    client.SetPin("pin used for pairing");
    client.BeginConnect(devInfo.DeviceAddress, BluetoothService.SerialPort, BluetoothClientConnectCallback, client);
}

private void BluetoothClientConnectCallback(IAsyncResult ar)
{
    var bluetoothClient = ar.AsyncState as BluetoothClient;
    bluetoothClient.EndConnect(ar);
    UpdateUI("Connected");

    var stream = bluetoothClient.GetStream();
...

但此时:bluetoothClient.EndConnect(ar); 我总是得到一个 SocketException,主要是说:“请求的地址在其上下文中无效

它很少说:

"连接尝试失败,因为连接的一方在一段时间后没有正确响应,或者连接失败,因为连接的主机没有响应"

您能否提出一些可能导致该问题的建议?

4

1 回答 1

0

对我来说,在连接开始时改变线路就足够了

client.BeginConnect(info.DeviceAddress, BluetoothService.SerialPort,
new AsyncCallback(BCCCallback), client);

它必须是一个 asyncCallback

于 2016-06-23T21:39:02.130 回答