Hello again,
I am still getting problems with my server and client program, this time I can’t sync the server with the client. The client just hears the server and prints it. Here is the code
import processing.net.*;
Client cln;
int data;
void setup() {
size(500,500);
cln = new Client(this,"ip adress",5204);
}
void draw() {
if (cln.available() > 0) {
data = cln.read();
print(data);
print(" / ");
}
}
and the server is
import processing.net.*;
Server serv;
Client player1;
Client player2;
Client player3;
Client player4;
void setup() {
serv = new Server(this,5204);
while (serv.clients[0] == null) {
}
player1 = serv.clients[0];
while (serv.clients[1] == null) {
waiting(2);
}
player2 = serv.clients[1];
while (serv.clients[2] == null) {
waiting(3);
}
player3 = serv.clients[2];
while (serv.clients[3] == null) {
waiting(4);
}
player4 = serv.clients[3];
}
void waiting(int pl) {
serv.write(90 + (pl - 1));
}
again I am just showing a smaller version. Note that I made a change in the code, that’s because in the other code the client wouldn’t connect directly to the player, it goes to an array before you can assign it.
The problem here is that the client can’t sync, if I run the server and the client in this order SERVER then CLIENT normally, no debug the client won’t print anything but if I put a breakpoint in this line
player1 = serv.clients[0];
then I press continue it will work fine, I can even stop the client and run it again and it will still work. I tried putting a delay here:
player1 = serv.clients[0];
delay(10);
I even tried using different values like 100, even 10000.
If anybody have an idea on how to solve this would be helpful.