write unsigned integer 32 bits to socket

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rkmr.em@gmail.com

    write unsigned integer 32 bits to socket

    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(s ocket.AF_INET, socket.SOCK_STR EAM)
    >>s.connect(('1 27.0.0.1',3000) )
  • Larry Bates

    #2
    Re: write unsigned integer 32 bits to socket

    rkmr.em@gmail.c om 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(s ocket.AF_INET, socket.SOCK_STR EAM)
    >>>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

    Comment

    • rkmr.em@gmail.com

      #3
      Re: write unsigned integer 32 bits to socket

      On Sun, Jul 27, 2008 at 7:01 PM, Larry Bates <larry.bates@we bsafe.com`wrote :
      rkmr.em@gmail.c om 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\x 03'

      this is long
      >>struct.pack(' !l',3)
      '\x00\x00\x00\x 03'

      Comment

      • Larry Bates

        #4
        Re: write unsigned integer 32 bits to socket

        rkmr.em@gmail.c om wrote:
        On Sun, Jul 27, 2008 at 7:01 PM, Larry Bates <larry.bates@we bsafe.com`wrote :
        >rkmr.em@gmail.c om 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\x 03'
        >
        this is long
        >>>struct.pack( '!l',3)
        '\x00\x00\x00\x 03'
        Short is 16 bits, Integer is 32 bits, long is 64 bits (as I read and have found).

        -Larry

        Comment

        • rkmr.em@gmail.com

          #5
          Re: write unsigned integer 32 bits to socket

          On Sun, Jul 27, 2008 at 7:17 PM, Larry Bates <larry.bates@we bsafe.com`wrote :
          rkmr.em@gmail.c om wrote:
          >On Sun, Jul 27, 2008 at 7:01 PM, Larry Bates <larry.bates@we bsafe.com`>
          >wrote:
          >>rkmr.em@gmail.c om 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(us32bi t)
          >>
          >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.

          Comment

          Working...