Good Evening,
I'm currently testing AS3+NodeJS communication to delve into multiplayer games. I'm currently very experienced in Flash, but pretty new to NodeJS.
The problem I have is that the data that Node sends is different to what Flash Receives.
Take the following working NodeJS Code (I'm not asking if it is right or wrong or for "best practice" - im testing different things out). Look specifically at the 'clients' object and the "data" event handler:
var net = require('net');
var mySocket;
var clients = {
'0': 'myTest'
};
var server = net.createServer(function(socket) {
mySocket = socket;
mySocket.on("data", function(data){
myData = data + " -- " + clients[0];
console.log("Data=" + myData);
mySocket.write(myData);
});
});
server.listen(3000, "127.0.0.1");
When "hello world" data is sent to the server the expected output is this:
Console: "Data=hello world--myTest"
Flash: "Data Received: [hello world--myTest]"
The console outputs the information that i am expecting, however the Flash outputs :-
"Data Received: [ -- myTesthello world]"
A few snippets from my AS3 Connection Class is below :-
public function createConnection():void{
this.currStatus = "Connecting..";
this.mySocket = new XMLSocket("localhost",3000);
this.mySocket.addEventListener(DataEvent.DATA, onReceiveData);
For handling data that is received, we just trace it for now:
private function onReceiveData(evt:DataEvent):void{
//We have recieved some data from the server. Act upon it..
//not sure yet what it will do with the data.. just trace for now.
trace("Data Received: [" + evt.data + "]");
}
If anyone can point out why the data is in a different order when received in Flash, it would be a good learning point. As I said im very new to NodeJS so there may be something i am missing (I am aware there is no .on"connect".... took it out to test w/o it).
Thanks in advance.