Packet parsing problem...

Darrell news at dorb.com
Mon Feb 26 19:38:39 EST 2001


When parsing C structs use the struct model.

import struct
header = .........

fmt2="!II"
fmt2Size=struct.calcsize(fmt2)
fmt3="!III"

if len(header) == fmt2Size:
    values = struct.unpack(fmt2, header)
else:
    values = struct.unpack(fmt3, header)

--Darrell

"Brian Geddes" <brian.j.geddes at intel.com> wrote in message
news:97ek6i$o6d at news.or.intel.com...
> Here's my situation:
>
> There is an already-existing server (written in C++), which communicates
> with clients through 1-packet messages.  Each packet consists of a header
of
> 2 or 3 C++ DWORDs, followed by 0 to n bytes of data.  I have to write a
> Python client to communicate with this server.
>
> In python, is there any structure that approximates the C++ DWORD?  I need
> to be able to parse incoming packets, as well as properly form messages to
> the server.
>
> Any suggestions?
>
> Thanks,
> - Brian
>
>





More information about the Python-list mailing list