2

I'm trying to communicate with a bluetooth device as a client using 32feet.NET. The device is actually a microcontroller with a bluetooth module but currently I'm using my windows phone for testing. The devices are already paired and here's what I did. (devinfo is the DeviceInfo of the selected device)

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();
...

But at this point: bluetoothClient.EndConnect(ar); I always get a SocketException mostly saying: "The requested address is not valid in its context"

and rarely it says:

"A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond"

Could you suggest something that might cause the issue?

Peter
  • 1,047
  • 2
  • 18
  • 32
  • did you get the solution? I am trying to send message to Android smart phone. while executing BluetoothClient.Connect() method it shows me error stating "The requested address is not valid in its context". Well, the same works on my bluetooth audio dongle. – meekash55 Nov 10 '22 at 18:10

1 Answers1

0

For me was enough to change the line at the beginning of the connection with

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

it just had to be an asyncCallback