import socket
tcp_server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
tcp_server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
tcp_server_socket.bind(('', 8081))
tcp_server_socket.listen(128)
while 1 :
server_socket, addr = tcp_server_socket.accept()
recv_data = server_socket.recv(100000)
print(recv_data.decode())
response_line = 'HTTP/1.1 200 OK\r\n'
response_header = 'server:py1.0\r\n'
response_body = 'hi ! kun zhi \nWelcome to request Wen Jia Hao Server!'
response_data = response_line + response_header + "\r\n" +response_body
server_socket.send(response_data.encode('utf8'))
server_socket.close()
web服务器
最新推荐文章于 2024-11-06 17:55:14 发布