初识HTML

复制代码
 1 #!/usr/bin/env python
 2 import socket
 3 def handle_request(client):
 4     buf = client.recv(1024)
 5     client.sendall(bytes("HTTP/1.1 201 OK\r\n\r\n","utf8"))
 6     with open("a.html") as f:
 7         data = f.read()
 8     client.sendall(bytes(data,"utf8"))
 9 
10 def main():
11     sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
12     sock.bind(('localhost',8082))
13     sock.listen(5)
14 
15     while True:
16         connection, address = sock.accept()
17         handle_request(connection)
18         connection.close()
19 
20 if __name__ == '__main__':
21 
22     main()
复制代码

a.html文件内容:

<h1 style='color:green'>Hello, World</h1>
posted @   失落的黎明  阅读(125)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示