Skip to content

Buffers and Socket.io #5034

@Rainforce15

Description

@Rainforce15

I am running into some issues with v0.13+:

There's some code with socket.io that works with node v5/6 without issue, yet creates odd behaviour in nw.js - namely, it seems that one is unable to send buffers after a socket is stored in a variable/reused after the initial code context has ended. This likely happens on the socket.io-client side, considering how using an older version of nw.js as client does not create this issue in our project.

Test code that can be run with node or nw.js (creates and writes to a log file. also, required package.json can be minimal):

function log (msg) {
    require('fs').appendFile("log.txt", msg + "\n", function (err) {
        if (err) console.warn("cannot write to log file: " + err);
    });
}

var io = require('socket.io')();
io.on('connection', function(socket){
    function testLoop(i) {
        log("testing:" + i);
        socket.emit("test", {
            buff: new Buffer([1,2,3,4,5,6])
        });
        setTimeout(testLoop.bind(null, (i+1)), 1000);
    }

    testLoop(0);
});
io.listen(9000);

var socket = require('socket.io-client')('http://localhost:9000');
socket.on('connect', function(){
    log("client connected");
});

socket.on('test', function(data){ log(require('util').inspect(data)); });

expected behaviour (works in node v5/6):
the log shows something like

testing:0
{ buff: <Buffer 01 02 03 04 05 06> }
testing:1
{ buff: <Buffer 01 02 03 04 05 06> }
testing:2
{ buff: <Buffer 01 02 03 04 05 06> }
testing:3
{ buff: <Buffer 01 02 03 04 05 06> }

nw.js behaviour:

testing:0
{ buff: <Buffer 01 02 03 04 05 06> }
testing:1
testing:2
testing:3

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions