python是个什么东西---python---python的httpsever
时间:2010-07-13 来源:metallica-1860
# -*- coding:UTF-8 -*- import os import BaseHTTPServer import time import threading import urlparse class ServerHandler(BaseHTTPServer.BaseHTTPRequestHandler): # def __init__(self,request, client_address, server): # BaseHTTPServer.BaseHTTPRequestHandler.__init__(self,request, client_address, server) # self.server = server #处理用户的GET请求 def do_GET(self): try: str = urlparse.urlparse(self.path) fn = self.path print "address_string : " + self.address_string() print "path : " + fn print "query : " + str.query #写回客户端 self.wfile.write("111") except: print u'出现异常' self.send_error(404, 'File Not Found:%s' % fn) class Server: def startServer(self): server_address = ('', 8080) httpd = BaseHTTPServer.HTTPServer(server_address, ServerHandler) server_thread = threading.Thread(target=httpd.serve_forever) server_thread.setDaemon(True) server_thread.start() class HttpStart: def start(self): server = Server() server.startServer() starttime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())) print u'%s 服务器已启动' % starttime
相关阅读 更多 +