By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,826 Members | 1,135 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,826 IT Pros & Developers. It's quick & easy.

write unsigned integer 32 bits to socket

P: n/a
hi
i want to send unsigned 32 bit integer to socket, and looking for
something equivalent to this method...

http://livedocs.adobe.com/flex/2/lan...teUnsignedInt()

is there such method / library available in python?!
this is as far as i have gotten along
>>s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('127.0.0.1',3000))
Jul 28 '08 #1
Share this Question
Share on Google+
4 Replies

P: n/a
rk*****@gmail.com wrote:
hi
i want to send unsigned 32 bit integer to socket, and looking for
something equivalent to this method...

http://livedocs.adobe.com/flex/2/lan...teUnsignedInt()

is there such method / library available in python?!
this is as far as i have gotten along
>>>s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('127.0.0.1',3000))
You will need to use struct module to build the 4 byte value and then send it.

Something like (not tested):

import struct
us32bit = struct.pack("I", value)
s.send(us32bit)

-Larry
Jul 28 '08 #2

P: n/a
On Sun, Jul 27, 2008 at 7:01 PM, Larry Bates <la*********@websafe.com`wrote:
rk*****@gmail.com wrote:
>i want to send unsigned 32 bit integer to socket, and looking for
something equivalent to this method...
http://livedocs.adobe.com/flex/2/lan...teUnsignedInt()

is there such method / library available in python?!
You will need to use struct module to build the 4 byte value and then send
it.

Something like (not tested):

import struct
us32bit = struct.pack("I", value)
s.send(us32bit)
thanks a lot!!!

just to make sure if I want 32 bit or 4 bytes then should I use the
short or integer or long?

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

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

this is long
>>struct.pack('!l',3)
'\x00\x00\x00\x03'
Jul 28 '08 #3

P: n/a
rk*****@gmail.com wrote:
On Sun, Jul 27, 2008 at 7:01 PM, Larry Bates <la*********@websafe.com`wrote:
>rk*****@gmail.com wrote:
>>i want to send unsigned 32 bit integer to socket, and looking for
something equivalent to this method...
http://livedocs.adobe.com/flex/2/lan...teUnsignedInt()

is there such method / library available in python?!
You will need to use struct module to build the 4 byte value and then send
it.

Something like (not tested):

import struct
us32bit = struct.pack("I", value)
s.send(us32bit)

thanks a lot!!!

just to make sure if I want 32 bit or 4 bytes then should I use the
short or integer or long?

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

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

this is long
>>>struct.pack('!l',3)
'\x00\x00\x00\x03'
Short is 16 bits, Integer is 32 bits, long is 64 bits (as I read and have found).

-Larry
Jul 28 '08 #4

P: n/a
On Sun, Jul 27, 2008 at 7:17 PM, Larry Bates <la*********@websafe.com`wrote:
rk*****@gmail.com wrote:
>On Sun, Jul 27, 2008 at 7:01 PM, Larry Bates <la*********@websafe.com`>
wrote:
>>rk*****@gmail.com wrote:
i want to send unsigned 32 bit integer to socket, and looking for
something equivalent to this method...

http://livedocs.adobe.com/flex/2/lan...teUnsignedInt()

is there such method / library available in python?!

You will need to use struct module to build the 4 byte value and then
send
it.

Something like (not tested):

import struct
us32bit = struct.pack("I", value)
s.send(us32bit)

thanks a lot!!!

just to make sure if I want 32 bit or 4 bytes then should I use the
short or integer or long?

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

'\x00\x03'

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

'\x00\x00\x00\x03'

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

'\x00\x00\x00\x03'

Short is 16 bits, Integer is 32 bits, long is 64 bits (as I read and have
found).
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.
Jul 28 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.