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.
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.
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.