write unsigned integer 32 bits to socket

Michael Torrie torriem at gmail.com
Mon Jul 28 01:52:24 EDT 2008


rkmr.em at gmail.com wrote:
> thanks a lot!!! re-read it again!!!
> 
> from the struct doc!
> Standard size and alignment are as follows: no alignment is required
> for any type (so you have to use pad bytes); short is 2 bytes; int and
> long are 4 bytes; long long (__int64 on Windows) is 8 bytes; float and
> double are 32-bit and 64-bit IEEE floating point numbers,
> respectively.

Of course any time you send coherent numbers over the network, I highly
recommend you use what's called network byte order.  In C, you'd use the
 htonl() call, and then when pulling it off the wire on the other end
you'd use ntohl().  If you don't then you will have problems when the
endianness is different between the hosts.  Standard convention (even in
the MS word) is to use big-ending across the network.  I'm sure python
has some convention in the struct module for dealing with this.



More information about the Python-list mailing list