anks257
anks257

Reputation: 85

How does BluetoothServerSocket.accept() work?

So I just wanted to get my concepts cleared. How exactly does BluetoothServerSocket.accept() exactly work? The Android documentation mentions that it returns a CONNECTED BluetoothSocket, but isn't there some kind of authorization before connecting?

Also, I am currently working on an application where one device acts as a host and holds a listening BluetoothServerSocket, but I want to first list down all the incoming client connections and let the user select which device to connect with. Is that possible? If yes, how can it be done?

Thanks in advance. :)

Upvotes: 1

Views: 1346

Answers (1)

Tom
Tom

Reputation: 17854

You would have to implement those things.

Bluetooth has its own security, including authorization, encryption, etc. If the security of Bluetooth is not sufficient for your purposes then you need to implement your own.

Bluetooth sockets is a simple abstraction for communicating over Bluetooth RFCOMM (or L2CAP on other platforms). It doesn't add any security, or any ability to select amongst clients.

If you want to let the user choose amongst possible clients to connect with then you will probably want to accept() connections from multiple clients (so that you have multiple independent Bluetooth socket connections). Have each client use the socket to identify itself and then list these for the user who can then select who to communicate with.

If you want something easier, but less secure, you could just show the user a list of paired devices, or do a scan and show them the list of devices found in the scan, and then let the user pick from this list. But be aware that other devices can mis-identify themselves.

Upvotes: 1

Related Questions