我的个人服务器(python socket服务器)
效果:
代码如下:
import socket
def main():
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sock.bind(('localhost',8000))
print('listening....')
sock.listen(5)
while True:
conn,addr = sock.accept()
data = conn.recv(1024)
print(data)
conn.send(b"HTTP/1.1 200 OK\r\nContent-Type:text/html;charset=utf-8\r\n\r\n")
conn.send("<h1>这个是我的个人服务器</h1>\r\n电脑前的您长的很帅很漂亮!".encode("utf-8"))
conn.close()
if __name__ =="__main__":
main()