Теперь я вижу, что Дафф упоминал простой HTTP-сервер, но я привел пример того, как вы решите свою проблему (используя BaseHTTPServer
):
<code>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
'% params)
если __name__ == '__main__':
server_class = BaseHTTPServer.HTTPServer
httpd = server_class ((HOST_NAME, PORT_NUMBER), MyHandler)
пытаться:
httpd.serve_forever ()
кроме KeyboardInterrupt:
проходить
httpd.server_close ()
Теперь, из вашего JavaScript, вы бы позвонили http://localhost:1337/?color=ffaabb