2 Replies Latest reply on Nov 20, 2009 1:24 AM by 1ndivisible

    Passing a ByteArray through a socket to a Python server

    1ndivisible Level 1

      Hi,

       

      I've written a simple Python(2.6) server that I am connecting to from an AIR app using Socket. I can successfully send text and numbers through, but when I try and send a 3 byte ByteArray through using mySocket.writeBytes(myByteArray), I receive the ByteArray as a String. More specifically the String 'A f'.

       

      My question is should it be possible to send a ByteArray through the socket, and if so, can anyone suggest where the problem might lie?

       

      Thanks in advance.

        • 1. Re: Passing a ByteArray through a socket to a Python server
          jake_flex

          When you serialize the ByteArray on the AIR app, I believe the format is such that it can only be read with another application that understands the serialization format. I can give you three options for a solution

           

          1. Look for a deserialization library for Python. If the serialization format is AMF, then look at pyAMF

          2. Write your own serialization methods

          3. Use JSON for serializing the data

           

          P.S. Are you sure you are receiving all the data sent? When using recv() function, you might not get all data sent with the first call.

          1 person found this helpful
          • 2. Re: Passing a ByteArray through a socket to a Python server
            1ndivisible Level 1

            Hi,

             

            Thanks for replying.

             

            I actually managed to get the data I needed, but in convoluted way. FIrst split the String into its 3 characters, then passed them all to this function that I found on a forum somewhere:

             

            def byteToHex(self, byteStr ):
                 return ''.join( [ "%02X " % ord( x ) for x in byteStr ] ).strip()

             

            This returned hex values for each byte which I could use as I needed.