def main(): HOST_NAME = iotUtils.getDeviceIP() server_class = BaseHTTPServer.HTTPServer while True: try: httpd = server_class((HOST_NAME, SERVER_PORT), MyHandler) print "HTTP_SERVER: " + time.asctime(), "Server Starts - %s:%s" % (HOST_NAME, SERVER_PORT) httpd.serve_forever() except (KeyboardInterrupt, Exception) as e: print "HTTP_SERVER: Exception in HttpServerThread (either KeyboardInterrupt or Other)" print ("HTTP_SERVER: " + str(e)) iotUtils.switchBulb("OFF") httpd.server_close() print "HTTP_SERVER: " + time.asctime(), "Server Stops - %s:%s" % (HOST_NAME, SERVER_PORT) print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' pass
def main(): HOST_NAME = iotUtils.getDeviceIP() HTTP_SERVER_PORT = iotUtils.getHTTPServerPort() server_class = BaseHTTPServer.HTTPServer while True: try: httpd = server_class((HOST_NAME, HTTP_SERVER_PORT), OnRequestListener) print "HTTP_SERVER: " + time.asctime(), "Server Starts - %s:%s" % (HOST_NAME, HTTP_SERVER_PORT) httpd.serve_forever() except (KeyboardInterrupt, Exception) as e: print "HTTP_SERVER: Exception in HttpServerThread (either KeyboardInterrupt or Other)" print ("HTTP_SERVER: " + str(e)) if running_mode.RUNNING_MODE == "N": iotUtils.switchBulb("OFF") else : iotUtils.switchBulb("OFF") httpd.server_close() print "HTTP_SERVER: " + time.asctime(), "Server Stops - %s:%s" % (HOST_NAME, HTTP_SERVER_PORT) print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' pass