hex sending

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • hiroc

    #1

    hex sending

    s.send("abc") # send test string

    I need to send hex:"10 06 00 0f 02 bc d1" instead of "abc"

    hoW?

  • Fredrik Lundh

    #2
    Re: hex sending

    "hiroc" wrote:
    s.send("abc") # send test string
    >
    I need to send hex:"10 06 00 0f 02 bc d1" instead of "abc"
    do you want to send seven binary bytes, or pairs of hexadecimal characters
    separated by whitespace ?

    how do you map from "abc" to "10 06 00 0f 02 bc d1", by the way? what
    encoding is that?

    </F>



    Comment

    • hiroc

      #3
      Re: hex sending

      I want send pairs of hexadecimal characters, abc is only my test hex
      char is real





      Fredrik Lundh wrote:
      "hiroc" wrote:
      >
      s.send("abc") # send test string

      I need to send hex:"10 06 00 0f 02 bc d1" instead of "abc"
      >
      do you want to send seven binary bytes, or pairs of hexadecimal characters
      separated by whitespace ?
      >
      how do you map from "abc" to "10 06 00 0f 02 bc d1", by the way? what
      encoding is that?
      >
      </F>

      Comment

      • Stoune

        #4
        Re: hex sending


        hiroc wrote:
        I want send pairs of hexadecimal characters, abc is only my test hex
        char is real
        >
        Possibly this code helps to you:

        import binascii

        binascii.hexlif y('hello worlds')

        Output: '68656c6c6f2077 6f726c6473'

        Comment

        • Tim Roberts

          #5
          Re: hex sending

          "hiroc" <hiroc13@hotmai l.comwrote:
          >s.send("abc" ) # send test string
          >
          >I need to send hex:"10 06 00 0f 02 bc d1" instead of "abc"
          >
          >hoW?
          One ugly way is
          s.send( "\x10\x06\x00\x 0f\x02\xbc\xd1" )
          --
          - Tim Roberts, timr@probo.com
          Providenza & Boekelheide, Inc.

          Comment

          • Paul Rubin

            #6
            Re: hex sending

            "hiroc" <hiroc13@hotmai l.comwrites:
            s.send("abc") # send test string
            I need to send hex:"10 06 00 0f 02 bc d1" instead of "abc"
            See the binascii module:

            import binascii

            # a2b_hex stands for "ascii to binary conversion, hex format"
            # you must remove the spaces
            binary = binascii.a2b_he x ("1006000f02bcd 1")

            s.send (binary)

            Comment

            Working...