PDA

View Full Version : Binary Socket



PsuFan
March 8th, 2009, 03:29 PM
Hello,

Everyone claims that they have a binary socket using the Socket() class but I havent found any that work properly.

I have tried var sData = socket.readUTFBytes(sock.bytesAvailable); which works fine for plain text, but when you send it binary it doesnt work. (sData.length = 0)

I have also tried socket.readBytes(sReceive, 0, socket.bytesAvailable); and then convertered to a string. I thought this method was working but it turns out its not because a Byte in AS3 = -128 to 127. So when you encode a binary character (From 0 to 255) AS3 displays garbage when it gets a value higher then 127. Since the server cant encode binary from -128 to 127 because its ASCII. Has anyone run into this?

Thanks

PsuFan
March 8th, 2009, 03:50 PM
hmm seems after I posted this, I found the answer after doing a little more searching on Adobe.

readUnsignedByte()method
public function readUnsignedByte():uint (http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/uint.html)
Language Version : ActionScript 3.0Runtime Versions : AIR 1.0, Flash Player 9

Reads an unsigned byte from the socket.

Returns uint (http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/uint.html) — A value from 0 to 255.