write unsigned integer 32 bits to socket

rkmr.em at gmail.com rkmr.em at gmail.com
Mon Jul 28 15:02:48 CEST 2008

On Mon, Jul 28, 2008 at 5:45 AM, Scott David Daniels
<Scott.Daniels at acm.org> wrote:
> Alan Franzoni wrote:
>> Michael Torrie was kind enough to say:
>>> Of course any time you send coherent numbers over the network, I highly
>>> recommend you use what's called network byte order....  I'm sure python
>>> has some convention in the struct module for dealing with this.
>> Not in the struct module; such functions are available in the socket
>> module, and should be employed indeed.
> Please don't pass this misinformation along.
> In the struct module document, see the section on the initial character:
>    Character Byte order Size and alignment
>      @          native            native
>      =          native           standard
>      <       little-endian       standard
>      >        big-endian         standard
>      !    network (= big-endian) standard
>  and notes @ is the default.
>>>> print struct.pack('<lh', 3,4)
>>>> print struct.pack('>lh', 3,4)
>>>> print struct.pack('lh', 3,4)
>>>> print struct.pack('!lh', 3,4)

thanks for clarifying, and just to make sure, i am using '!' format
from the struct package... i had this even in my previous email....
what am doing below is fine right?

this is short
>>> struct.pack('!h',3)

this is integer
>>> struct.pack('!i',3)

this is long
>>> struct.pack('!l',3)

More information about the Python-list mailing list