Hi Tyler, With a binary protocol such as that that might be created with struct.pack, you could include the packet length as the first 2 or 4 bytes of the message. Alternatively, you could an ASCII protocol, for example, by pickling the objects and encoding them with base64. You could then make a file-like object out of the socket and use the high-level read/readline functions. --Jim ----- Original Message ----- From: Tyler Littlefield <tyler@xxxxxxxxxxxxx> To: <programmingblind@xxxxxxxxxxxxx> Sent: Sunday, May 24, 2009 9:25 AM Subject: data serialization and transport using python:protocol question > Hello list, > I've got a quick question. > I was looking at using the struct module to serialize some data for > transportation through a socket or a pipe, and was trying to figure out the > most efficient way of setting this up. > I'd like the max length of a message to be 4096, which is 4 kb in size. > Now, when I set this up, I can pad with zeros, but that means that for every > message, whether it's 3 chars long or 500 chars long, I still have all that > extra overhead. > Is there an easier way to do this that wouldn't be so bandwidth consuming? > 4 kb may not be much, but it'll get rough if there are multiple people > connecting to the same server. > I'd thought about keeping the length of the data and adding that to the top > of the struct, then decompressing using that, but I'd have to unpack the > structure twice, unless there is a way I can just read the int off the top, > and do something like: > ">dd"+str(length)+"s" etc... > > > Thanks, > Tyler Littlefield > Web: tysdomain.com > email: tyler@xxxxxxxxxxxxx > My programs don't have bugs, they're called randomly added features. > > __________ > View the list's information and change your settings at > //www.freelists.org/list/programmingblind > ---------------------------------------------------------------------------- "Information in this email (including attachments) is confidential. It is intended for receipt and consideration only by the intended recipient. If you are not an addressee or intended recipient, any use, dissemination, distribution, disclosure, publication or copying of information contained in this email is strictly prohibited. Opinions expressed in this email may be personal to the author and are not necessarily the opinions of the HSE. If this email has been received by you in error we would be grateful if you could immediately notify the ICT Service Desk by telephone at +353 1 6352757 or by email to service.desk@xxxxxx and thereafter delete this e-mail from your system" ---------------------------------------------------------------------------- __________ View the list's information and change your settings at //www.freelists.org/list/programmingblind