Great news! And thanks for the reply.
Well... this is the stripped down version of the code im using for testing on the server side. Its built around one of the examples.
final String SERVICE_NAME = "myService";
Bluetooth bt;
boolean connected = false;
Client[] misclientes = new Client[0];
void setup(){
size(600,300);
background(0);
bt = new Bluetooth(this);
bt.start(SERVICE_NAME);
}
void draw(){
if (connected == true){
for(int i = 0; i < misclientes.length; i++){
if(misclientes[i].available() > 0){
recibido = misclientes[i].readInt();
println(recibido);
}
}
}
}
void clientConnectEvent(Client client){
misclientes = (Client[])append(misclientes, (Client) client);
conectado = true;
}
void keyPressed(){
println(misclientes.length);
for(int i = 0; i < misclientes.length; i++){
println(misclientes[i].device.name);
misclientes[i].write(1);
flush();
}
}
The first cellphone client has no problems finding the service and connecting. The second cant find the service at all. This is what the cellphone does:
final String SERVICE_NAME = "myService";
boolean conectado = false;
Bluetooth bt;
PFont font;
String[] msgs = new String[90];
Client server;
int recibido = 0;
String temporal = "";
int temporal2;
void setup(){
font = loadFont();
textFont(font);
p = new Phone(this);
bt = new Bluetooth(this,0x0003);
bt.find();
for (int i = 0; i < length(msgs); i++){
msgs[i] = "-";
}
}
void draw(){
background(0);
fill(255);
for (int i2 = 0; i2 < length(msgs); i2++){
text(msgs[i2], 4, 25+15*i2+6);
}
if (conectado == true){
if (server.available() > 0){
recibido = (int)server.read();
}
}
}
void libraryEvent(Object library, int event, Object data){
if (library == bt){
if (event == Bluetooth.EVENT_DISCOVER_SERVICE_COMPLETED ){
Service[] services = (Service[])data;
for (int i = 0; i < length(services); i++){
msgs[i] = "Servicio: " + services[i].name;
temporal = services[i].name;
temporal2 = temporal.indexOf(SERVICE_NAME);
if (temporal2 == 0){
try {
server = services[i].connect();
conectado = true;
return;
}
}
}
}
}
}
void keyPressed(){
if (conectado == true){
server.writeInt((int)key);
server.flush();
}
}
At first I tought the problem might be that the service cound only connect to one client at a time. If that was the case, the solution might have been creating more than one service, and more than one bt object, so i changed the server to this:
bt[0] = new Bluetooth(this);
And on every ClientConnectEvent:
bt = (Bluetooth[])append(bt, new Bluetooth(this));
bt[bt.length].start(SERVICE_NAME + "any character");
I managed to create two simultaneous services (cant create more). The first one connects to the first object created fine. But the second couldnt see neither.
So...
I have the feeling i am doing wrong something simple, that there is something im doing wrong on the clientConnectEvent. Its great news to know I only need one service, makes the code cleaner.
Thanks!