help on packet format for tcp/ip programming

rattan at cps.cmich.edu rattan at cps.cmich.edu
Wed Feb 7 20:25:17 EST 2007


I want a specific packet format for packet exchange between a client
server across the network. For example frame format
as a python class could be:
class Frame:
        def __init__(self, buffer=None, count=0, offset=0):
                self.buffer = buffer
                self.count = count
                self.offset = offset
the question is how to convert it to a byte stream so that format of
count and offset also becomes a sequence of bytes. I tried
the pickle module as:
 a = Frame()
dat = pickle.dumps(a)
but the size of dat is quite large almost to 4 X the size of a, which
probably is an overkill for the numbers of bytes exchanged. Is there a
simpler solution (similar to C language -- set aside a buffer and fill
it with bytes and network byteorder values for count and offset and
send it out, there is no increase in byte count in the outgoing
packet)?

Any pointers will be appreciated.
-ishwar




More information about the Python-list mailing list