Weasel Projecta comet service on steroides

subscribe us now

Coding Day #4 - flash chunks

14
May
0

Workstations

On the last coding day we tested our weasel test rpg demo with two macs and one windows pc. Abrupt the windows pc doesnt load the map or other objects correctly. After debugging the windows client we find out that the javascript get small chunks and not the full package.  So whats going on !? Apparently the windows read buffer is smaller then the mac read buffer.  So the problem occurred. Whats the solution? Right …. drinking beer

Problem description:

1. Server write 5mb string into the stream (map format)

2. Flash received only the read buffer size from the os (in this case 1mb) That means flash doesent received one big package but five small chunks (package size / os read buffer)

3. Flash calls the javascript function for each chunk

4. The javascript gets an chunk from the package and cannot handle it

Solution:

The flash receiver must handle the cunks and build the completed package

Flash receiver

function socketData(e:ProgressEvent):void {
    // @TODO handle chunks
    // build the complete package, then call javascript
    var str:String = e.currentTarget.readUTFBytes(e.currentTarget.bytesAvailable);
    ExternalInterface.call("Weasel.dispatch",str);
}

Javascript dispatcher

	dispatch : function(json) {
		var cmds = json.split("|CMD|");
		var cmd = "";
		for each (var cmd in cmds) {
			if(cmd != "") {
				var response = JSON.parse(cmd),
					request,
					stack = Weasel._getRequestStack();
 
				if(response.type == "request") {
					Weasel._commands[response.command](response.params);
				} else {
					request = stack[response.commandId];
					request.callback(response.params);	
				}	
			}
		}
	},

Coding Day #4

Coding Day #2/3

27
Apr
0