write unsigned integer 32 bits to socket

Scott David Daniels Scott.Daniels at Acm.Org
Mon Jul 28 14:45:38 CEST 2008


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)




More information about the Python-list mailing list