try:
    port = 5555
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.bind(("", port))

    print "waiting on port:", port

    data = bytearray(10)

    while True:
        s.recvfrom_into(data)

        direction = data[0]
        angle = struct.unpack_from('<d', data, 1)[0]

        if direction == 0:
            car.stop()
        elif direction == 1:
            car.forward()
        elif direction == 2:
            car.backward()

        car.stear(angle)
except KeyboardInterrupt:
    pass
except:
    raise
finally:
    car.cleanup()
예제 #2
0
파일: server.py 프로젝트: 3m00ns/SSRascar
                cmd = ""

            # Move onto next character
            i += 1


##
## Main starting piont of server
## 
running = True
try:
    while running:
        print "Waiting ..."
        # Wait to accept a connection from client control app
        conn, addr = s.accept()
        print 'Connected with ' + addr[0] + ':' + str(addr[1])

        # Start listening to new socket on seperate thread
        start_new_thread(clientthread ,(conn,))
  
finally:
    print "Exiting"
    try:
        car.stop()  # Stop the car if we get here in error
    except:
        pass
    s.close()
    time.sleep(0.1) # wait a little for threads to finish
    car.cleanup()