Newbie: implementing lowlevel protocol over socket int32 data handling

John Roth newsgroups at jhrothjr.com
Thu Jul 31 17:10:01 CEST 2003


"Bram" <b.neijt at ai.rug.nl> wrote in message
news:bgbaj5$kgv$2 at news4.tilbu1.nb.home.nl...
> Hi,
> Summ: "What is the best way to handle int8,16 and 32 data in python?"
>
> Im currently working on a class to implement the gui protocol of
> mldonkey. (http://mldonkey.lemmster.de/wiki/index.php/GuiProtocol)
> However this requires to send int32 and int16 and even int8 integers.
>
> To create data I'm using the work-around of converting everything to hex
> values, and then converting the hex values to a data string which I put
> on the socket (e.g. "\x00\xF0").
> I could do the same on the recieving end: chop it up in bytes and
> convert them to numbers (combining the hi and lo bytes of the int16 with
> some calculations)
>
> However, there must be a better way of doing this.
> Can anyone help me on this problem?

I took a quick look at the Wiki describing the protocol. For
something like this, I'd expect that interoperability would be
an issue, so the actual data format in the packets would be
part of the protocol specification.

That being the case, look at the struct module. I think it does
exactly what you need.

John Roth
>
> Bram
>
>
>






More information about the Python-list mailing list