Skip to content

Commit

Permalink
fixed sizedMode in jsSocket2 (socket.readUTF() throws EOFError when c…
Browse files Browse the repository at this point in the history
…omplete string is not available)
  • Loading branch information
tmm1 committed Jan 22, 2009
1 parent 72e1a45 commit c0e8a87
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions flash/JsSocket.hx
Expand Up @@ -3,6 +3,7 @@ class JsSocket {
static var id:String;
static var buffer:String = "";
static var sizedReads:Bool = false;
static var packetSize:Int = -1;
static var slash:EReg = ~/\\/g;

private static function calljs(type, data:Dynamic) {
Expand Down Expand Up @@ -46,8 +47,26 @@ class JsSocket {

socket.addEventListener(flash.events.ProgressEvent.SOCKET_DATA, function(d){
if (sizedReads) {
while (socket.bytesAvailable > 0)
calljs('onData', slash.replace(socket.readUTF(), '\\\\'));
while (socket.bytesAvailable > 0) {
// figure out the packet size
if (packetSize > -1) {
// we have it already
} else if (socket.bytesAvailable >= 2) {
// read the packet size
packetSize = socket.readShort();
} else {
// lets wait
break;
}

// read the packet, if possible
if (socket.bytesAvailable >= packetSize) {
calljs('onData', slash.replace(socket.readUTFBytes(packetSize), '\\\\'));
packetSize = -1;
} else {
break;
}
}
} else {
var size = socket.bytesAvailable;
var data = new flash.utils.ByteArray();
Expand Down
Binary file modified flash/jsSocket2.swf
Binary file not shown.

0 comments on commit c0e8a87

Please sign in to comment.