1 #using threads to implement server-side response to multiple clients simultaneously2 #! -*-Conding:utf-8-*-3 ImportSocket4 ImportThreading5 Import Time6Addr= ("127.0.0.1", 8808)7conn=Socket.socket ()8 Conn.connect ((addr))9 defPro (AA):Tendata = CONN.RECV (1024) One Print(Str (data, encoding="Utf-8")) A -Conn.sendall (bytes (AA, encoding="Utf-8")) - while1: theAA = input ("Please enter \ n") - - Pro (AA) - conn.close () + - + ImportSocket A ImportThreading at Import Time -Addr= ("127.0.0.1", 8808) -conn=Socket.socket () - Conn.bind ((addr)) -Conn.listen (5) - defClient (CONN1): inConn1.send (Bytes ("welcom to Server", encoding="Utf-8")) - while1: toDATA=CONN1.RECV (1024) + #if not data: - # Break theConn1.sendall (Data+bytes ("Server Received", encoding="Utf-8")) * Print("OK") $ conn1.close ()Panax Notoginseng - whileTrue: theSock,ar=conn.accept () + Print(AR) AA=threading. Thread (target=client,args=(sock,)) the A.start () + #A.join () - Print("Biaoji")
Using threads to implement the socket service side to respond to multiple clients simultaneously