我有这个代码创建一个简单的套接字服务器Python.But它每次客户端断开时关闭,如何让它永远运行?
import socket
HOST = ''
PORT = 8000
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
conn, addr = s.accept()
with conn:
print('Connected by', addr)
while True:
data = conn.recv(1024)
print(data)
conn.sendall('HelloClient'.encode())
if not data:
continue