print('client got[% ]replyup to bytes in message if __name__ ='__main__'from threading import thread sthread thread(target=serversthread daemon true don' wait for server thread sthread start(do wait for children to exit for in range( )thread(target=clientargs=('client%si,)start(study this script' code and comments to see how the socket objectsmethods are used to transfer data in nutshellwith this type of socket the server accepts client connectionwhich by default blocks until client requests serviceand returns new socket connected to the client once connectedthe client and server transfer byte strings by using send and receive calls instead of writes and readsthough as we'll see later in the booksockets can be wrapped in file objects much as we did earlier for pipe descriptors also like pipe descriptorsunwrapped sockets deal in binary bytes stringsnot text strthat' why string formatting results are manually encoded again here here is this script' output on windowsc:\pp \system\processessocket_preview py client got[ "server got[ 'client ']"client got[ "server got[ 'client ']"client got[ "server got[ 'client ']"client got[ "server got[ 'client ']"client got[ "server got[ 'client ']"this output isn' much to look atbut each line reflects data sent from client to serverand then back againthe server receives bytes string from connected client and echoes it back in larger reply string because all threads run in parallelthe order in which the clients are served is random on this machine sockets and independent programs although sockets work for threadsthe shared memory model of threads often allows them to employ simpler communication devices such as shared names and objects and queues sockets tend to shine brighter when used for ipc by separate processes and independently launched programs example - for instancereuses the server and client functions of the prior examplebut runs them in both processes and threads of independently launched programs example - pp \system\processes\socket-preview-progs py ""same socketbut talk between independent programs toonot just threadsserver here runs in process and serves both process and thread clientssockets are machine-globalmuch like fifosdon' require shared memory ""from socket_preview import serverclient parallel system tools both use same port number