Python Server Code   

Python Server Code #===============================================================================
#Prototype AJAX Test: Server side script (start first)
#USAGE: <port>
#Gardette julien, June 2007
import sys
import SimpleHTTPServer
import SocketServer
import random
from time import gmtime, localtime

def startHTTPServer(port):
  Minimal web server.
  Serves files relative to the current directory and only one file: fileNameToAllow
  Expects "POST" requests from the scripted fileNameToAllow

  class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
    def __init__(self, request, client_address, server):
        SimpleHTTPServer.SimpleHTTPRequestHandler.__init__(self, request, client_address, server)

        #    def parse_request(self):
        #      print 'Raw', self.raw_requestline
        #      SimpleHTTPServer.SimpleHTTPRequestHandler.parse_request(self)
        #      print 'Command', self.command
        #      print 'Path', self.path
        #      print 'Version', self.request_version
        #      print 'Headers', self.headers

    def do_GET(self):
                """ Allow users to access the XML/Javascript front-end in Firefox """
                f = self.send_head()
                if f:
                    self.copyfile(f, self.wfile)

              #self.wfile.write("Access Denied\nHTTP Server:" + __file__ + "\n")
    def do_POST(self):
        if (self.path=="/init"):
  httpd = SocketServer.TCPServer(("", port), Handler)
  print "HTTP server is now serving at port", port
if __name__ == '__main__':
  if(len(sys.argv) == 2):
    port = int(sys.argv[1])
    port = 8080

Maintained by Julien Gardette. Last Modified: 2008/09/10 00:03:05.