I am trying to make pong online, but the client on the server side is always null. What can I do to fix this?
import processing.net.*;
Server pong;
int bounceTimer = 0;
int startTimer = 165;
int score1 = 0;
int score2 = 0;
int timeDisplay;
int clientNum = 0;
String input;
int data[];
int id = 0;
int move = 0;
Ball ball = new Ball(300, 200);
Paddle paddle1 = new Paddle(30, 200);
Paddle paddle2 = new Paddle(570, 200);
void setup() {
size(600, 400);
frameRate(55);
pong = new Server(this, 5204);
}
void draw() {
input = "";
timeDisplay = (startTimer/55) + 1;
if (startTimer < 0) {
timeDisplay = -1;
}
bounceTimer++;
background(0);
Client client = pong.available();
if (client != null) {
println("true");
input = client.readString();
switch (input) {
case "UP1":
paddle1.y -= 5;
break;
case "DOWN1":
paddle1.y += 5;
break;
case "UP2":
paddle2.y -= 5;
break;
case "DOWN2":
paddle2.y += 5;
break;
default:
break;
}
} else {
println("false");
}
if (startTimer > -1 && clientNum >= 2) {
startTimer--;
textSize(50);
text(timeDisplay, width/2 -15, height/2 -100);
}
ball.act();
paddle1.act();
paddle2.act();
textSize(23);
text(score1, 5, 25);
text(score2, width-20, 25);
pong.write(
(int)paddle1.y + " " +
(int)paddle2.y + " " +
(int)ball.x + " " +
(int)ball.y + " " +
(int)score1 + " " +
(int)score2 + " " +
(int)timeDisplay + " " +
(int)clientNum);
}
void serverEvent(Server server, Client client) {
clientNum++;
}