Actionscript xmlsocket doesn't read data which is write by the nodejs net module server. but server read the data correctly. any solution?

175 views Asked by At

Node js net module server code:

var net = require('net');
var server = net.createServer(function (connection) {
    console.log('client connected');

connection.on('data', function (data) {
    console.log('data from flash = ' + data);

    var jsonData = {};
    jsonData.message = "joined";

    var d = JSON.stringify(jsonData);

    connection.write(d);

});

connection.on('end', function () {
    console.log('client disconnected');
});

// connection.pipe(connection);
});
server.listen(3055, function () {
    console.log('server is listening');
});

Action script code

this.login_socket.connect(this.server_ip,3055);
         this.login_socket.addEventListener(Event.CONNECT,this.login_socket_onConnection);
         this.login_socket.addEventListener(DataEvent.DATA,this.login_onData);
         this.login_socket.addEventListener(IOErrorEvent.IO_ERROR,this.login_socket_onIOErrorEvent);
         this.login_socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR,this.login_socket_SecurityErrorEvent);
         this.login_socket.addEventListener(Event.CLOSE,this.login_socket_closeErrorEvent);

Can anyone please tell me how to use xml socket with node js net module? I have tried everything but this doesn't work at all. I want to create a socket connection for a flash game to the server. I am using laravel as backend. If anyone knows how to create it with php tell me. Thank you.

1

There are 1 answers

0
b8x On BEST ANSWER
var net = require('net');

var server = net.createServer(function (connection) {

    console.log('client connected');

    connection.setEncoding("utf8");

    // on receive data from client
    connection.on('data', function (data) {

        console.log('data from flash = ' + data);

        var d = JSON.stringify({
            message: "joined"
        }) + "\0";

        connection.write(d);
    });

    // on connection end
    connection.on('end', function () {
        console.log('client disconnected');
    });

    // on error
    connection.on("error", function (exception) {
        console.log('an error occurred: ' + exception);
    });
});

server.listen(3055, function () {
    console.log('server is listening');
});

I change nodejs server code to above code and it works fine now.