python中一个简单的webserver
2024-10-21 02:48:23
python中一个简单的webserver 2013-02-24 15:37:49
分类: Python/Ruby
支持多线程的webserver
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#!/usr/bin/python from SocketServer import ThreadingMixIn from BaseHTTPServer import HTTPServer,BaseHTTPRequestHandler class myHandler(BaseHTTPRequestHandler): #Handler for the GET requests def do_GET( self ): self .send_response( 200 ) self .send_header( 'Content-type' , 'text/html' ) self .send_header( 'Uri' , self .path) self .end_headers() self .wfile.write( "hi multi threading test!\n" ) class ThreadingHttpServer(ThreadingMixIn, HTTPServer): pass PORT_NUM = 8080 serverAddress = ("", PORT_NUM) server = ThreadingHttpServer(serverAddress, myHandler) print 'Started httpserver on port ' , PORT_NUM server.serve_forever() |
测试:
curl -v http://127.0.0.1:8080/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
[root@localhost ~]# curl -v http://127.0.0.1:8080/ * About to connect() to 127.0.0.1 port 8080 * Trying 127.0.0.1... connected * Connected to 127.0.0.1 (127.0.0.1) port 8080 > GET / HTTP/1.1 > User-Agent: curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5 > Host: 127.0.0.1:8080 > Accept: */* > < HTTP/1.0 200 OK < Server: BaseHTTP/0.3 Python/2.4.3 < Date: Sun, 24 Feb 2013 07:28:46 GMT < Content-type: text/html < Uri: / hi multi threading test! * Closing connection #0 |
最新文章
- MongoDB的基本操作
- lodash 替换 underscore
- PHP学习笔记:数据库学习心得
- Codeforces Round #145 (Div. 2, ACM-ICPC Rules)
- Netsharp快速入门(之15) 销售管理(报表B 销售季度表)
- POJ 1222
- Office OpenXML-Excel(一)
- OCM读书笔记(2) - PL/SQL 基础
- 【单源最短路模板】 poj 2387
- WPF中使用Data Annotations验证Model
- java(11)带参数的方法
- Flutter 页面入栈和出栈
- ASCII到Unicode到UTF-8
- kubernetes学习笔记之十:RBAC
- 发现一个好玩的东西 Web Scraper
- JSF web.xml的各类参数属性配置
- LeetCode题解之 Implement strStr()
- Xcode真机调试iOS10中Nslog 打印不出东西
- vue 的调试工具
- CentOS 下 安装 nginx
热门文章
- 阶段3 2.Spring_10.Spring中事务控制_8 spring基于纯注解的声明式事务控制
- Unity3D 旋转
- ROS自动切换策略
- USACO2.1 Hamming Codes【枚举+二进制处理+输出格式+题意理解】
- 【Python开发】【神经网络与深度学习】网络爬虫之图片自动下载器
- python 列表的(总结)
- 二、Kubernetes_V1.10集群部署-master-etcd
- javaScript中==和===对数组、对象的判断是它们是否同一个实例对象
- 均值滤波器(平滑空间滤波器)基本原理及Python实现
- Python细节(二)小数据池