although sockets are one of the most commonly used ipc toolsit' impossible to fully grasp their api without also seeing its role in networking because of thatwe'll defer most of our socket coverage until we can explore their use in network scripting in this section provides brief introduction and previewso you can compare with the prior section' named pipes ( fifosin shortlike fifossockets are global across machinethey do not require shared memory among threads or processesand are thus applicable to independent programs unlike fifossockets are identified by port numbernot filesystem path namethey employ very different nonfile apithough they can be wrapped in file-like objectand they are more portablethey work on nearly every python platformincluding standard windows python in additionsockets support networking roles that go beyond both ipc and this scope to illustrate the basicsthoughexample - launches server and clients in threads running in parallel on the same machineto communicate over socket--because all threads connect to the same portthe server consumes the data added by each of the clients example - pp \system\processes\socket_preview py ""sockets for cross-task communicationstart threads to communicate over socketsindependent programs can toobecause sockets are system-widemuch like fifossee the gui and internet parts of the book for more realistic socket use casessome socket servers may also need to talk to clients in threads or processessockets pass byte stringsbut can be pickled objects or encoded unicode textcaveatprints in threads may need to be synchronized if their output overlaps""from socket import socketaf_inetsock_stream port host 'localhostportable socket api port number identifies socket on machine server and client run on same local machine here def server()sock socket(af_inetsock_streamsock bind((''port)sock listen( while trueconnaddr sock accept(data conn recv( reply 'server got[% ]data conn send(reply encode()def client(name)sock socket(af_inetsock_streamsock connect((hostport)sock send(name encode()reply sock recv( ip addresses tcp connection bind to port on this machine allow up to pending clients wait for client to connect read bytes data from this client conn is new connected socket send bytes reply back to client connect to socket port send bytes data to listener receive bytes data from listener interprocess communication