python服务器
来源:互联网 发布:mac用什么炒股软件 编辑:程序博客网 时间:2024/06/06 12:22
python最原始服务器
import socketdef handle_request(client): buf = client.recv(1024) client.send("HTTP/1.1 200 OK\r\n\r\n".encode('utf-8')) client.send("Holle".encode('utf-8'))def main(): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bind(('localhost', 8000)) sock.listen(5) while True: connection, address = sock.accept() handle_request(connection) connection.close()if __name__ == '__main__': main()
利用python模块进行创建服务器
from wsgiref.simple_server import make_serverdef RunServer(environ, start_response): # environ 客户发来的所有数据 # start_response 封装要返回给用户的数据,响应有状态 start_response('200 OK', [('Content-Type', 'text/html')]) # 返回的内容 return [bytes('<h1>Hello, web!</h1>', encoding='utf-8'), ]if __name__ == '__main__': httpd = make_server('', 8000, RunServer) print("Serving HTTP on port 8000...") httpd.serve_forever()
阅读全文
0 0
- python服务器
- Python服务器开发(1)
- PYTHON 创建WEB服务器
- python版本的服务器
- python 访问LDAP服务器
- python聊天服务器实现
- python简单网络服务器
- python 搭建服务器
- python 服务器 select 游戏
- PYthon多线程服务器
- python 日志收集服务器
- python epoll开发服务器
- python twisted聊天服务器
- python,开启django服务器
- python搭建服务器
- Python Redis数据结构服务器
- python twisted 建立服务器
- python 服务器日志分析
- msp430g2553 time1
- 黑客界“两会”的演讲稿与开源工具
- 20171026memo
- python 读取中文文件名/中文路径
- java入门篇---自增自减、三元运算符+for循环、if判断
- python服务器
- java AES加密解密
- UltraEdit查看class的jdk版本
- dataTables自增序号的实现
- 多种类布局的适配器及优化
- 项目中遇到的bug
- centos7.2 PHP7安装mysql 扩展
- Codeforces Round #131 (Div. 2) / 214A System of Equations 暴力枚举
- windows上用apache做反向代理