help on packet format for tcp/ip programming
Diez B. Roggisch
deets at nospam.web.de
Thu Feb 8 10:27:35 EST 2007
> Grant had the right idea, I think, but he failed to actually include a
> byte length in his format. :) So there's nothing to peek at. If the
> packing is done like this, instead..
>
>
> struct.pack('!IIL', len(buffer), count, offset) + buffer
>
> Then it is a simple matter to unpack it once the receiving side, by
> waiting for struct.calcsize('!IIL') bytes, using struct to get
> len(buffer), count, and offset:
>
> length, count, offset = struct.unpack('!IIL', bytes)
>
> And then waiting for `length' more bytes, which will be the buffer.
That was my intention, yes - I thought the header information of the OP
contained a byte count already.
> I'm not sure what the original use-case was here. XML-RPC isn't a good
> transport for arbitrary binary data. If `buffer' contains text, though,
> that might be a good suggestion.
Certainly XMLRPC isn't too good - and Pyro in many aspects better. AFAIK it
uses pickle, and that means that things should be comparably compact.
Diez
More information about the Python-list
mailing list