I see now that Daff mentioned the simple HTTP server, but I made an example on how you'd solve your problem (using BaseHTTPServer
):
import BaseHTTPServer
HOST_NAME = 'localhost'
PORT_NUMBER = 1337
class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(s):
s.send_response(200)
s.send_header('Content-Type', 'text/html')
s.end_headers()
# Get parameters in query.
params = {}
index = s.path.rfind('?')
if index >= 0:
parts = s.path[index + 1:].split('&')
for p in parts:
try:
a, b = p.split('=', 2)
params[a] = b
except:
params[p] = ''
# !!!
# Check if there is a color parameter and send to controller...
if 'color' in params:
print 'Send something to controller...'
# !!!
s.wfile.write('<pre>%s</pre>' % params)
if __name__ == '__main__':
server_class = BaseHTTPServer.HTTPServer
httpd = server_class((HOST_NAME, PORT_NUMBER), MyHandler)
try:
httpd.serve_forever()
except KeyboardInterrupt:
pass
httpd.server_close()
Now, from your JavaScript, you'd call http://localhost:1337/?color=ffaabb