# python client

# import create.py
from time import sleep
from socket import * 

serverHost = 'localhost'             # I think this client code is what made
serverPort = 2000                    # me a Python believer

s = socket(AF_INET, SOCK_STREAM)     # create a TCP socket 
s.connect((serverHost, serverPort))  # connect to server on the port 

robot = None

# 
# the main control loop
#
while True:

    message = raw_input("Type a string to send: ")
    
    if message == 'q': # just quits the client
        break
        
    if message == 'connect' and robot == None:
        # set up robot
        pass
        # else robot = None
        
    if message[0:3] == 'go ' and robot != None:
        speed = int( message[3:] )  # cm per second
        robot.go( speed )
        
    if message[0:5] == 'turn ' and robot != None:
        speed = int( message[3:] )  # degrees per second
        robot.go( 0.0, speed )
    
    if message[0:8] == 'mainloop': # and robot != None:
        try:
            while True:
                print 'mainloop'
                sleep(1)
                pass
        except:
            print "Control-c caught. Continuing with the user loop."

    s.send(message) #send the data 
    received = s.recv(1024) #receive up to 1K bytes 
    print "I received the message: ", received 

    if message == 'quit': # to quit the server, too
        break






print 'Good bye!'

