代码实现:
index页面:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
hello,hi!------------------------------------
</body>
</html>
main页面:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
main page
</body>
</html>
服务器文件application.py:
import socket
import threading
from response import HttpResponse
from request import HttpRequest
# WSGI服务器
class WSGIServer():
def __init__(self, host='localhost', port=8080, connectSize=100):
'''
:param port: 服务器的端口号
:param connectSize: 默认的并发数量
'''
self.__host = host
self.__port = port
self.__connectSize = connectSize
pass

本文展示了如何使用Python通过socket实现一个基于TCP的简单WebServer,并实现了WSGI接口。服务器能处理GET请求,返回index和main两个页面的内容。
最低0.47元/天 解锁文章
594

被折叠的 条评论
为什么被折叠?



