conn send(('server % got [% ]\ (mypiddata)encode()def client ()mypid os getpid(redirectbothasclient(for in range( )print('client % % (mypidi)print to socket data input(input from socketflushessys stderr write('client % got [% ]\ (mypiddata)not redirected ##############################################################################redirect client input outputclient is socket server ##############################################################################def server ()mypid os getpid(sock socket(af_inetsock_streamsock connect((hostport)file sock makefile(' 'for in range( )sock send(('server % % \ (mypidi)encode()data file readline(rstrip(print('server % got [% ](mypiddata)send to input(recv from print(result to terminal def client ()mypid os getpid(redirectbothasserver( ' actually the socket server in this mode for in range( )data input(input from socketflushesprint('client % got [% ](mypiddata)print to socket sys stdout flush(else last buffered till exit##############################################################################redirect client input outputclient is socket clientserver xfers first ##############################################################################def server ()mypid os getpid(test but server accepts conn initlistenersocket(wait for client connect file conn makefile(' 'send input()recv print(for in range( )conn send(('server % % \ (mypidi)encode()data file readline(rstrip(print('server % got [% ](mypiddata)def client ()mypid os getpid( redirectbothasclient( ' the socket client in this mode for in range( )data input(input from socketflushesprint('client % got [% ](mypiddata)print to socket sys stdout flush(else last buffered till exit##############################################################################making sockets look like files and streams