效果:

我的个人服务器(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()


 

相关文章:

  • 2022-01-22
  • 2021-12-25
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
  • 2022-12-23
  • 2022-12-23
  • 2021-11-07
猜你喜欢
  • 2021-11-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-31
  • 2021-11-02
  • 2022-02-14
相关资源
相似解决方案