First, the server-side implementation:
__author__ = Socketthreadingtcplink (sock, addr): (% addr) sock.send (): data = Sock.recv (). Sleep () Data Data.decode () = =: Sock.send ((% Data.decode ()). Encode ()) sock.close () (% addr) Server = Socke T.socket (socket.af_inet, socket. SOCK_STREAM) HOST = PORT = Server.bind ((HOST, PORT)) Server.listen () (): SOCK, addr = server.accept () t = Threading. Thread (=tcplink, = (sock, addr)) T.start ()
Second, the implementation of the client:
__author__ = Socketsock = Socket.socket (socket.af_inet, socket. SOCK_STREAM) HOST = PORT = Sock.connect ((HOST, PORT)) (Sock.recv (). Decode ()) data [,,,,]: sock.send (data) (Sock.rec V (). Decode ()) Sock.send () Sock.close ()
This article is from the "Time Traveler" blog, so be sure to keep this source http://siweilai.blog.51cto.com/9233507/1775057
Python Socket server and client