文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>python是个什么东西---python---python的httpsever

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
 
相关阅读 更多 +
排行榜 更多 +
找茬脑洞的世界安卓版

找茬脑洞的世界安卓版

休闲益智 下载
滑板英雄跑酷2手游

滑板英雄跑酷2手游

休闲益智 下载
披萨对对看下载

披萨对对看下载

休闲益智 下载