我正在努力让nodevs / socket.io / express在ARMv5TE处理器上的busybox linux上运行。我有nodejs启动并运行,以下代码运行没有错误。
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);
});
});
直到我尝试通过websocket从客户端连接。从浏览器(加载了客户端脚本socket.io.js
),var socket = io.connect('ws://192.168.1.8:3000');
或var socket = io.connect('http://192.168.1.8:3000');
。 Node然后将此错误记录到控制台并停止:
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)
从我的台式计算机(Windows 8 64位)运行相同的节点服务器不会产生此错误。
我可以将错误跟踪到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);
...
如果我将rand.writeInt32BE(this.sequenceNumber, 11);
更改为rand.writeInt32BE(this.sequenceNumber, 11, true);
,则错误就会消失,我可以毫无问题地继续(大概)。所以:
base64id.js
的更改是安全还是合适?