[Tutor] Buffer code review

Danny Yoo dyoo at hashcollision.org
Fri Feb 12 11:55:36 EST 2016

Hi Richard,

Make sure you understand the semantics of socket.send.  It does *not*
guarantee that it sends all the data, and the comment you have in your

> def sendLine(line, i):
>     s =  '\x02' + line[:-1] + '\x03'
>     logging.info('sending line ' + str(i))
>     print i
>     socktx.send(s)  # send the entire line to the socket
>     f2.write(s + '\n')
> #    time.sleep(0.2)
>     return

isn't actually true: depending on the conditions on the socket, it may
not send all the bytes in s.  See:
https://docs.python.org/2/library/socket.html#socket.socket.send for
more details.

More information about the Tutor mailing list