file " :\pp \internet\sockets\test-stream-modes py"line in writeropen('temp''wb'fails on printbinary mode file " :\pp \internet\sockets\test-stream-modes py"line in writer print( 'spam'typeerrormust be bytes or buffernot str :\pp \internet\socketstest-streams-binary py "" '"""\ spam traceback (most recent call last)file " :\pp \internet\sockets\test-stream-modes py"line in writeropen('temp'' ' fails on opentext must be valueerrorcan' have unbuffered text / the same rules apply to socket wrapper file objects created with socket' makefile method--they must be opened in text mode for print and should be opened in text mode for input if we wish to receive text stringsbut text mode prevents us from using fully unbuffered file mode altogetherfrom socket import socket(defaults to tcp/ip (af_inetsock_streams makefile(' ' this used to work in python traceback (most recent call last)file " :\python \lib\socket py"line in makefile valueerrorunbuffered streams must be binary line buffering text-mode socket wrappers also accept buffering-mode argument of to specify linebuffering instead of the default full bufferingfrom socket import socket( makefile(' ' same as buffering= but acts as fully bufferedthis appears to be no different than full bufferingand still requires the resulting file to be flushed manually to transfer lines as they are produced consider the simple socket server and client scripts in examples - and - the server simply reads three messages using the raw socket interface example - pp \internet\sockets\socket-unbuff-server py from socket import sock socket(sock bind(('' )sock listen( print('accepting 'connid sock accept(read three messages over raw socket blocks till client connect for in range( )print('receiving 'making sockets look like files and streams