def run(self):
        print "Client is starting"
        #Create Configurations
        near,far = self.getConfigurations()
        engine = AutoPerformanceEngine(near)

        #Send Configuration
        self.sendConfiguration(far.toString())
        
        try:
            #Start the server
            engine.startServer()
            
            #Send Run TCP
            self.sendTcpStart()
            dataNear,summaryNear = engine.runTcp()
            dataFar ,summaryFar  = self.receiveTcpResupts()
            self.ouputTcpToFile(dataNear, dataFar, summaryNear, summaryFar)
            
            #Send Run Udp
            self.sendUdpStart()
            summaryNear = engine.runUdp()
            summaryFar  = self.receiveUdpResults()
            self.ouputUdpToFile(summaryNear, summaryFar)
            
        except:
            print "AutoPerformance::Client::Error: an exception occured in client::run()"
        finally:
            #stop the server
            engine.stopServer()
            print "AutoPerformance::Client::Done on client side."
        
        print "Client is finishing now."
 def handle(self):
     '''
     Handle the incoming connection
     '''
     configStr = self.request.recv(1024)
     config = AutoPerformanceConfig()
     config.fromString(configStr)
     config.host = self.request.getpeername()[0]
     
     print "Server is using peer name of: ", config.host
     
     engine = AutoPerformanceEngine(config)
     
     #Start our server
     try:
         engine.startServer()
     
     
         runCmd = self.request.recv(10)
         if(str(runCmd) != 'tcp'):
             print "Error: unexpected request. Aborting: recv:", runCmd
             return
         data, summaryTcp = engine.runTcp()
         self.sendTcpResults(data, summaryTcp)
         
         runCmd = self.request.recv(10)
         if(str(runCmd) != 'udp'):
             print "Error: unexpected request. Aborting recv:", runCmd
             return
         summaryUdp = engine.runUdp()
         self.sendUdpResults(summaryUdp)
     
     finally:
         #stop server
         print "Done on server side."
         self.request.close()
         engine.stopServer()
         self.finish()