Python之web服务器-返回固定数据(二)
import socket
if __name__ == '__main__':
tcp_server_socket = socket.socket(socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
tcp_server_socket.bind(("", 9090))
tcp_server_socket.listen(128)
while True:
service_client_socket, ip_port = tcp_server_socket.accept()
http_request_data = service_client_socket.recv(4096)
print(http_request_data)
response_line = "HTTP/1.1 200 OK\r\n"
response_header = "Server: p\PWS/1.1\r\nother:ok\r\nContent-Type: text/html;charset=utf-8: "
response_body = "word
"
response_content = response_line + response_header + "\r\n" + response_body
respose_data = respose_content.encode("utf-8")
service_client_socket.send(respose_data)
tcp_server_socket.close()