I connect multiple Bluetooth clients and store them in a list:
BluetoothListener blueListener = new BluetoothListener(mUUID);
blueListener.Start();
while (true)
{
try
{
//accept available clients for connection
BluetoothClient localClient = blueListener.AcceptBluetoothClient();
myClientList.Add(localClient);
}
catch(Exception e)
{ }
}
Now, when some client gets unexpectedly disconnected, I would like to remove it from the list. I tried to use the client's property 'LinkKey
' in order to detect the disconnected client, but I get runtime error.
An unknown, invalid, or unsupported option or level was specified in a getsockopt or setsockopt call
StackTrace = " at System.Net.Sockets.Socket.GetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, Int32 optionLength)\r\n at InTheHand.Net.Bluetooth.Msft.SocketBluetoothClient.get_LinkKey()\r\n
at MSBusinessLogicPack.BluetoothLogic.BTServerCl...
This exception occurs as soon as I try to get the LinkKey value, even while the client is still connected.
Here is the code that I use to remove the client from the list, assuming I have a way to identify the client, which I currently don't:
public override void ClientDisconnected(Guid clidenID)
{
int removeIndex = myClientList.FindIndex(x => x.LinkKey == clidenID);
myClientList.RemoveAt(removeIndex);
}