编程语言
首页 > 编程语言> > Python BS模式下的web应用程序扩展

Python BS模式下的web应用程序扩展

作者:互联网

#优化部分:将web展示部分分离server代码文件

 

 server:

# web应用程序
import socket

sock=socket.socket()
sock.bind(("127.0.0.1",8800))
sock.listen(5)

while 1:
print("server is working...")
conn,addr=sock.accept()
#接受请求数据
recv_data=conn.recv(1024)
print("recv_data\n",recv_data.decode())
with open("index.html","rb") as f:
data =f.read()
conn.send(b"HTTP/1.1 200 OK\r\n\r\n" + data)
conn.close()
sock.close()

index:

<h1>hi huchangxi</h1>
<img src="https://imgcps.jd.com/ling4/100026667910/5Lqs6YCJ5aW96LSn/5L2g5YC85b6X5oul5pyJ/p-5f3a47329785549f6bc7a6f5/15fd9fad/cr/s/q.jpg">

 

 

标签:web,Python,recv,sock,server,BS,data,conn
来源: https://www.cnblogs.com/A121/p/16274264.html