I need to develop an application that will allow devices to communicate from time to time (one device sends a simple message, another one sends a response).
This communication is not going to happen too often (once in several minutes), so it does not seem to be reasonable to keep a permanent connection between the devices. Besides, the connection may be lost for some reason, so I'm going to need a some sort of the recovery logic.
Instead, I'd prefer the app to establish a new connection each time it needs to send data to a peer. However, the specs say, that after BluetoothServerSocket.accept
returns, the server socket should be closed. This means that the app will no longer be able to receive the subsequent incoming connections.
Currently I'm thinking of not closing the server socket and processing the incoming connections in a synchronous manner, so that the app will not try to accept a new connection until the previous one is processed and closed. What will happen if another peer tries to connect in the middle of such processing? Will it fail or just block until server is ready to accept it?