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?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.