server.py:
#css主要是用于布局、颜色,js用于动作处理如图片轮换
import socket
def main():
sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sock.bind(('localhost',8080))
sock.listen(5)
while True:
connection,address=sock.accept()
buf=connection.recv(1024)
f=open('test.html','rb')
data=f.read()
connection.sendall(bytes('HTTP/1.1 201 OK
','utf8'))
connection.sendall(data)
connection.close()
if __name__ == '__main__':
main()
test.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>hello,jerry</h1>
<h2>hello,tom</h2>
<img src="123.jpg" height="185" width="181" />
</body>
</html>