print(msgblocks till data received gets all print lines at once unless flushed the client in example - sends three messagesthe first two over socket wrapper fileand the last using the raw socketthe manual flush calls in this are commented out but retained so you can experiment with turning them onand sleep calls make the server wait for data example - pp \internet\sockets\socket-unbuff-client py import time send three msgs over wrapped and raw socket from socket import sock socket(default=af_inetsock_stream (tcp/ipsock connect(('localhost' )file sock makefile(' 'buffering= default=full buff =error not linebuffprint('sending data 'file write('spam\ 'time sleep( #file flush(print('sending data 'print('eggs'file=filetime sleep( #file flush(print('sending data 'sock send( 'ham\ 'time sleep( must follow with flush(to truly send now uncomment flush lines to see the difference adding more file prints does not flush buffer either output appears at server recv only upon flush or exit low-level byte string interface sends immediately received first if don' flush other tworun the server in one window first and the client in another (or run the server first in the background in unix-like platformsthe output in the server window follows-the messages sent with the socket wrapper are deferred until program exitbut the raw socket call transfers data immediatelyc:\pp \internet\socketssocket-unbuff-server py accepting receiving 'ham\nreceiving 'spam\ \neggs\ \nreceiving 'the client window simply displays "sendinglines seconds apartits third message appears at the server in secondsbut the first and second messages it sends using the wrapper file are deferred until exit (for secondsbecause the socket wrapper is still fully buffered if the manual flush calls in the client are uncommentedeach of the three sent messages is delivered in serial seconds apart (the third appears immediately after the second) network scripting