Python Server Code   
   

Python Server Code

HTTPServer.py #===============================================================================
#Prototype AJAX Test: Server side script (start first)
#USAGE: main.py <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)
                    f.close()  

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

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