import threading
import socket
def client_thread(client_socket):
while 1:
data = client_socket.recv(2048)
if data :
print('接收到了客户端的数据:' + data.decode())
client_socket.send(data)
else:
print('客户端断开了连接')
client_socket.close()
break
def main():
server_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
server_socket.bind(('',10086))
server_socket.listen(128)
while 1:
client_socket,client_addr = server_socket.accept()
thd = threading.Thread(target = client_thread,args = (client_socket,))
thd.deamon = 1
thd.start()
if __name__ == "__main__":
main()