import socket
 
HOST, PORT = '', 8080

listen_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
listen_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
listen_socket.bind((HOST, PORT))
listen_socket.listen(1)
print 'Serving HTTP on port %s ...' % PORT
while True:
    client_connection, client_address = listen_socket.accept()
    request = client_connection.recv(1024)
    print request
    # Check what the request wants
    if "updateheader" in  request:
        f = open('/tmp/update/updateheader.html','r')
        output = f.read()
    elif "body" in request:
        f = open('/tmp/update/body.html', 'r')
        output = f.read()
    else:
        f = open('/tmp/update/mainpage.html', 'r')
        output = f.read()

    client_connection.send('HTTP/1.0 200 OK\n')
    client_connection.send('Content-Type: text/html\n')
    client_connection.send('\n') # header and body should be separated by additional newline
    client_connection.send(output)
    client_connection.close()
