I am implementing Bluetooth server, which supports multiple clients. I am using RFCOMM protocol. Is it possible to connect many clients for the same RFCOMM channel?
Server code for(C++):
int client;
std::list<boost::thread *> pool;
boost::thread *t;
struct sockaddr_rc loc_addr = { 0 }, rem_addr = { 0 };
socklen_t opt = sizeof(rem_addr);
int s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
loc_addr.rc_family = AF_BLUETOOTH;
loc_addr.rc_bdaddr = {0, 0, 0, 0, 0, 0};
loc_addr.rc_channel = (uint8_t) 1;
fflush(stdout);
bind(s, (struct sockaddr *) &loc_addr, sizeof(loc_addr));
fflush(stdout);
listen(s, 1);
while(1){
client = accept(s, (struct sockaddr *) &rem_addr, &opt);
cout << "Accepted " << endl;
t = new boost::thread(&read_data,client, this);
pool.push_back(t);
t->join();
}
read_data
is processing function for connection
Clients connects via this code(Java/Android):
...
BluetoothDevice mmDevice = mBluetoothAdapter
.getRemoteDevice(serverAddress);
String data;
Method m = mmDevice.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
clientSocket = (BluetoothSocket) m.invoke(mmDevice, 1);
...
Client from first device sucessfully connected and send/receive data from server. Client from second device succesfully connected to server. I can see this message in android log:
D/BluetoothEventLoop( 194): Device property changed: 00:15:83:3D:0A:57 property: Connected value: true
BUT no second "Accepted" message from server and no data received for second client after connection.