3

I am working on getting nodejs / socket.io / express running on busybox linux on an ARMv5TE processor. I have nodejs up and running and the following code runs without errors.

var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);

server.listen(80);

app.get('/', function (req, res) {
    res.sendfile(__dirname + '/index.html');
});

io.on('connection', function (socket) {
    socket.emit('news', { hello: 'world' });
    socket.on('my other event', function (data) {
        console.log(data);
    });
}); 

Until I try to connect via websocket from a client. From the browser (with the client script socket.io.js loaded), var socket = io.connect('ws://192.168.1.8:3000'); or var socket = io.connect('http://192.168.1.8:3000');. Node then logs this error to the console and stops:

buffer.js:784
    throw TypeError('value is out of bounds');

TypeError: value is out of bounds
    at TypeError (<anonymous>)
    at checkInt (buffer.js:784:11)
    at Buffer.writeInt32BE (buffer.js:924:5)
    at Base64Id.generateId (/usr/lib/node_modules/socket.io/node_modules/engine.io/node_modules/base64id/lib/base64id.js:88:8)
    at Server.handshake (/usr/lib/node_modules/socket.io/node_modules/engine.io/lib/server.js:222:21)
    at /usr/lib/node_modules/socket.io/node_modules/engine.io/lib/server.js:184:12
    at Server.checkRequest (/usr/lib/node_modules/socket.io/lib/index.js:67:51)
    at Server.verify (/usr/lib/node_modules/socket.io/node_modules/engine.io/lib/server.js:127:17)
    at Server.handleRequest (/usr/lib/node_modules/socket.io/node_modules/engine.io/lib/server.js:174:8)
    at Server.<anonymous> (/usr/lib/node_modules/socket.io/node_modules/engine.io/lib/server.js:362:12)

Running the same node server from my desktop computer (Windows 8 64 bit), does not produce this error.

I can trace the error to these lines of code in node_modules/socket.io/node_modules/engine.io/node_modules/base64id/lib/base64id.js:

Base64Id.prototype.generateId = function () {
    var rand = new Buffer(15); // multiple of 3 for base64
    if (!rand.writeInt32BE) {
        return Math.abs(Math.random() * Math.random() * Date.now() | 0).toString() + Math.abs(Math.random() * Math.random() * Date.now() | 0).toString();
    }
this.sequenceNumber = (this.sequenceNumber + 1) | 0;
rand.writeInt32BE(this.sequenceNumber, 11);
...

If I change rand.writeInt32BE(this.sequenceNumber, 11); to rand.writeInt32BE(this.sequenceNumber, 11, true);, the error goes away and I can continue on without problems (presumably). So:

  • Why does this error occur when running my code from the ARMv5TE machine?
  • Is my change to base64id.js safe or appropriate?
AnalogWeapon
  • 550
  • 1
  • 4
  • 16
  • Have you tried wrapping that object in a JSON.stringify so you have JSON.stringify({ hello: 'world' }) ? – Catalyst Jun 29 '14 at 05:43
  • I still get the same error. That code is lifted straight from the socket.io examples: http://socket.io/docs/ – AnalogWeapon Jun 29 '14 at 23:25
  • I copy pasted and it worked for me? the ports and ip had to be changed of course, but really that was it. – Catalyst Jun 30 '14 at 04:02
  • Did you run it with node on an ARMv5TE processor? This same code works fine for me when I run it with node on my Windows machine too. I think this is a problem with node on ARMv5TE specifically. – AnalogWeapon Jun 30 '14 at 04:55
  • 1
    That makes a lot of sense, it sounds like the socket.io native stuff is causing problems, in particular it could be the things in the ws dependency. Maybe try doing a basic example with the ws module to verify? there could also be some magic flag for node-gyp you could add in to change how things are compiled. I think it boils down to the platform specific size of certain types in the C++ code, but then again it could be much less complicated than that. – Catalyst Jun 30 '14 at 06:03

0 Answers0