Handling data on persistent connections

A new problem which our persistent connection approach raises is that we can no longer assume that our socket.recv() call will contain data from only one message. In our echo server, because of how we have defined the protocol, we know that as soon as we see a null byte, the message that we have received is complete, and that the sender won't be sending anything further. That is, everything we read in the last socket.recv() call is a part of that message.

In our new setup, we'll be reusing the same connection to send an indefinite number of messages, and these won't be synchronized with the chunks of data that we will pull from each socket.recv(). Hence, it's quite possible that the data from one recv()

Get Learning Python Network Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.