# send.py # # Send a 100MB message through a socket using two different techniques. # Run this program after receive.py has been started. from timethis import * from socket import * MSGSIZE = 1048576*100 # 100MB msg = b"x"*MSGSIZE s = socket(AF_INET,SOCK_STREAM) s.connect(("",20000)) with timethis("Send slices"): remaining = MSGSIZE while remaining > 0: nsent = s.send(msg[-remaining:]) remaining -= nsent # Wait for receiver ack ack = s.recv(1) with timethis("Send memory views"): view = memoryview(msg) while view: nsent = s.send(view) view = view[nsent:] s.close()