import socket
import sort
import control_motor
import control_pixel

host = 192.168.1.3 # socket.gethostname()
port = 9001                   # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
s.sendall(b'Connected to server!')
control_pixel.ledOn()
while True:
    try:
        data = s.recv(1024)
        if not data: break
        print("Found "+data)
        selectedBin = sort.sort(data)
        control_pixel.ledOff()
        control_motor.goToBin(selectedBin)
        control_pixel.ledOn()
        s.sendall(b'Continue')
    except socket.error:
        print("Error Occured.")
        break
s.close()