Mercurial > tote-had
changeset 17:d323ad02e8d1
Don't wait for the connection
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Mon, 11 Apr 2016 22:25:04 +0200 |
| parents | f753bc7165e0 |
| children | 8c572672fd5e |
| files | python/main.py python/server.py |
| diffstat | 2 files changed, 23 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/python/main.py Mon Apr 11 14:49:05 2016 +0200 +++ b/python/main.py Mon Apr 11 22:25:04 2016 +0200 @@ -1,9 +1,1 @@ -import network -import server - -wlan = network.WLAN(network.STA_IF) -ap = network.WLAN(network.AP_IF) -while not wlan.isconnected() and not ap.isconnected(): - pass - server.main()
--- a/python/server.py Mon Apr 11 14:49:05 2016 +0200 +++ b/python/server.py Mon Apr 11 22:25:04 2016 +0200 @@ -11,28 +11,31 @@ sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.setblocking(False) sock.bind(addr) - sock.listen(0) + sock.listen(1) robot = Robot() gait = Creep(robot) + run = gait.run() while True: - client, addr = sock.accept() - client.setblocking(False) - for frame in gait.run(): - command = client.read(1) - if command == b' ': - gait.dx = 0 - gait.dy = 0 - gait.rotation = 0 - elif command == b'w': - gait.dy = min(3, gait.dy + 0.25) - elif command == b's': - gait.dy = max(-3, gait.dy - 0.25) - elif command == b'a': - gait.rotation = min(math.pi/90, gait.rotation + math.pi/360) - elif command == b'd': - gait.rotation = max(-math.pi/90, gait.rotation - math.pi/360) - - - + try: + client, addr = sock.accept() + except OSError: + next(run) + else: + client.setblocking(False) + while True: + command = client.read(1) + if command == b' ': + gait.dx = 0 + gait.dy = 0 + gait.rotation = 0 + elif command == b'w': + gait.dy = min(3, gait.dy + 0.25) + elif command == b's': + gait.dy = max(-3, gait.dy - 0.25) + elif command == b'a': + gait.rotation = min(math.pi/90, gait.rotation + math.pi/360) + elif command == b'd': + gait.rotation = max(-math.pi/90, gait.rotation - math.pi/360) + next(run)
