I am running a server that accepts two clients and pairs them against each other in a battle simulation. When one player inputs a command I want my server to tell the other player that they're being waited on. The problem is that my server is very synchronized and doing this could upset the synchronization. Also the method that waits for the player to input a move uses a while loop in another class which prevents the player from checking if any information is being received until the loop ends (which would mean the player already inputted their move defeating the purpose of knowing the other person was waiting). Is there any way to use an input stream in a while loop that will instantaneously check if information is available and if not continue running the rest of the loop's code rather than waiting until it has something to receive and halting the code? That would solve my issue pretty easily.
public void buttonMove(InputStream in) {
move = "";
while(move == "") {
in.doSomething() // check for data from server but if not keep running
move = move;
}
card.setMove(move);
}
My buttons constantly listen for input and the program can't progress until the player inputs a move. I need to get input from the server (if available) while also continuing to run the entire loop.