transport mechanisms see for more details on object serialization interfaces more generallyany component that expects file-like method protocol will gladly accept socket wrapped with socket object makefile call such interfaces will also accept strings wrapped with the built-in io stringio classand any other sort of object that supports the same kinds of method calls as built-in file objects as always in pythonwe code to protocols--object interfaces--not to specific datatypes stream redirection utility to illustrate the makefile method' operationexample - implements variety of redirection schemeswhich redirect the caller' streams to socket that can be used by another process for communication the first of its functions connects outputand is what we used in the others connect inputand both input and output in three different modes naturallythe wrapper object returned by socket makefile can also be used with direct file interface read and write method calls and independently of standard streams this example uses those methodstooalbeit in most cases indirectly and implicitly through the print and input stream access built-insand reflects common use case for the tool example - pp \internet\sockets\socket_stream_redirect py ""##############################################################################tools for connecting standard streams of non-gui programs to sockets that gui (or otherprogram can use to interact with the non-gui program ##############################################################################""import sys from socket import port host 'localhostpass in different port if multiple dialogs on machine pass in different host to connect to remote listeners def initlistenersocket(port=port)""initialize connected socket for callers that listen in server mode ""sock socket(af_inetsock_streamsock bind((''port)listen on this port number sock listen( set pending queue length connaddr sock accept(wait for client to connect return conn return connected socket def redirectout(port=porthost=host)""connect caller' standard output stream to socket for gui to listen start caller after listener startedelse connect fails before accept network scripting