I have one tcp server and two connected clients. This is a tic tac toe game, so clients make their moves one-by-one. The server sends a packet to the client, to say that it allows to input, while the second client just wait. The problem is when the second client waiting it can write something, but it will not send to the server until its turns. server output. second client. So the problem is when turn turns to the second client and he wrote something before it, it's sent to the server. How can i "clear" everything before "Your turn, enter (row col)"
"Your turn, enter (row col)" - means server sent packet, and wait for user input
"Everything ok" - means user input delivered to the server
Server:
if is_x:
players[0].send(b'\0x01')
client_move = sock_manipulation.receive_move(players[0])
if client_move:
players[0].send('Everything ok'.encode())
print(f'Client move: {client_move}')
else:
print('Nothing received!')
is_x = False
else:
players[1].send(b'\0x01')
client_move = sock_manipulation.receive_move(players[1])
if client_move:
players[1].send('Everything ok'.encode())
print(f'Client move: {client_move}')
else:
print('Nothing received!')
is_x = True
Client:
while 1:
command = sock.recv(2048)
if command == b'\0x01':
move = pickle.dumps(input('Your turn, enter (row col): ').split())
sock.send(move)
accept = sock.recv(2048)
print(accept.decode())