@multiprocess无法启动
只需要加入
if name == “main”:
即可
from socket import *
from multiprocessing import Process
def handle(connd,addr):
print("客户端:",addr)
while True:
data = connd.recv(1024)
if not data:
break
print(data.decode())
connd.send(b'OK')
HOST ='0.0.0.0'
PORT =8888
ADDR = (HOST,PORT)
if __name__ == '__main__':
s = socket()
#重新释放端口
s.setsockopt(SOL_SOCKET,SO_REUSEADDR,1)
s.bind(ADDR)
s.listen(5)
while True:
print("等待新的连接")
try:
connd, addr = s.accept()
except KeyboardInterrupt:
print("退出服务端")
break
except Exception as e:
print(e)
continue
print(addr)
p = Process(target=handle,args=(connd,addr))
p.start()