Python实现简单的web server,pythonwebserver,这是Python实现的非
Python实现简单的web server,pythonwebserver,这是Python实现的非
这是Python实现的非常简单web server。
# Very Very Simple Web Server# This can be used to demonstrate how HTTP works!!# TO DO# create a simple html file# path = "C:/index.html"# open browser in address bar# http://127.0.0.1:50007/index.html#from socket import *HOST = '127.0.0.1' # Symbolic name meaning the local hostPORT = 50007 # Arbitrary non-privileged ports = socket(AF_INET,SOCK_STREAM)s.bind((HOST, PORT))#format of response message(DO NOT ALTER IF YOU DONT KNOW WHAT U R DOING)str ='''HTTP/1.0 200 OKConnection: closeContent-Length: 1Content-Type: text/html'''s.listen(1)while 1: conn, addr = s.accept() print 'Connected by', addr data = conn.recv(1024) if not data: break file = open(data[4:data[4:].find(' ')+4]) # extracts filename from request str1 = file.read() file.close() data = str +str1 conn.send(data) conn.close()
相关内容
- Python计算程序运行时间,python计算程序运行,使用time模
- python计算圆周率pi,python圆周率pi,from sys imp
- Python通过深拷贝实现从实例继承,python实例,Take an ins
- python刷新浪微博粉丝,python新浪博粉丝,之前有个哥们老
- python flatten sequences,flattensequences,A simple met
- python生成zip压缩文件目录结构,,下面python代码片段
- python里的签名方法hmac,python签名hmac,>>> import h
- 正则表达式断言学习,正则表达式断言,关于前瞻断言,
- import python 配置文件,importpython,这段代码演示使用imp
- Python 获取目录下的文件列表与内容,python获取,下面的
评论关闭