McSinyx / brutalmaze

Migrated to https://git.sr.ht/~cnx/brutalmaze
https://pypi.org/project/brutalmaze/
GNU Affero General Public License v3.0
11 stars 3 forks source link

Zombie hero when the client hangs #8

Closed nghiaxlee closed 6 years ago

nghiaxlee commented 6 years ago

When I tested the remote control, there was a time the hero was supposed to die but then the screen is continuing to move for a while even though the trigon disappeared? Not sure if my client program made mistake or not and it seems like the triangle will stop iff it got stuck: https://drive.google.com/open?id=1sZ06-bpfOOUhSHM1mvNiZm4O_ZPoWEIQ.

import socket

client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM);
client_socket.connect(('localhost', 8089))

while True:
    try:
        data = client_socket.recv(4096)
    except:
        break
    print(data.decode())
    inp = input()
    if len(inp) != 7:
        print("Error! Will stop")
        break
    sent = client_socket.send(inp.encode())

client_socket.close()

Edit by @McSinyx: clarify problem.

McSinyx commented 6 years ago

ace9586 (0.6.2) add timeout support so that the server can continue the flow and disable the hero properly. If you're insist on using manual input to talk with the server, do it in a threading.Thread (trust me, you don't wanna do this, it's lots more complicated than writing a simple AI) and have fallback message to send.

Additionally, although 4096 would be realistically enough, you should follow the docs, which allow you to recv up to 9999999 bytes of data. Also a small note on your program: len(inp) == 7 is not enough to validate the input (it could be smaller than 7 BTW), you should try to catch a ValueError on a, b, c = map(int, inp.split()); and in this case (not any more with the new change) you can simply put the input in a infinite loop and only break when the input is valid instead of quiting.

McSinyx commented 6 years ago

Is this solved now? Imma close it, but feel free to reopen.