import socket
import SocketServer
import RPi.GPIO as GPIO
import time

#server setting
host = socket.gethostbyname('172.20.10.5')
port = 8081

class EchoHandler(SocketServer.StreamRequestHandler):
    def handle(self):
        data = self.request.recv(1024).rstrip('\n')
        print "date:", time.ctime()
        print "recv data: %s\n" % data
        
        #light led
        if data == "star":
            GPIO.output( 17, True )
            time.sleep(0.3)
            GPIO.output( 17, False )
        
        self.request.send(data)
        self.request.close()

server = SocketServer.TCPServer((host, port), EchoHandler)

GPIO.setmode( GPIO.BCM )

#yellow
GPIO.setup(17, GPIO.OUT)
GPIO.output( 17, False )

server.serve_forever()
