答和泉纱雾
可以用python实现这个效果。
import socket
socket_server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socket_server.bind(("127.0.0.1", 80))
socket_server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
socket_server.listen(128)
while True:
socket_client, ip_addr = socket_server.accept()
data = socket_client.recv(100000)
if not len(data):
print("客户端关闭")
break
print(data.decode('utf-8'))
with open("1.png", "rb") as f:
music_data = f.read()
response_line = "HTTP/1.1 200 OK\r\n"
response_header = "Server: py1.0\r\n"
response_body = music_data
response_data = (response_line + response_header + "\r\n").encode() + response_body
socket_client.send(response_data)
socket_client.close()
把1.png这个图片文件放在与该代码同级的目录下即可实现