【问题标题】:Node.JS bug trying to create a chat尝试创建聊天的 Node.JS 错误
【发布时间】:2012-07-27 01:27:01
【问题描述】:

我目前正在编写一个将在 Heroku 上运行的聊天应用程序。我正在使用 Node.JS 和 Socket.IO 来完成这项任务。当我在本地运行它时它工作得很好,但是当我将它部署到 heroku 时,我得到了这个错误:

app[web.1]: /app/node_modules/socket.io/lib/manager.js:724
app[web.1]:   rand.writeInt32BE(this.sequenceNumber, 11);
app[web.1]:        ^
app[web.1]: TypeError: Object 

这里是 Socket.IO 部分的代码(剩下的只是经典的 Express 代码):

var socket = require('socket.io');
var io = socket.listen(app);

io.configure(function () { 
    io.set("transports", ["xhr-polling"]); 
    io.set("polling duration", 10); 
});

var usernames = {}

io.sockets.on('connection', function (socket) {
    socket.on('adduser', function(username) {
      socket.username = username;
      usernames[username] = username;
      socket.join('room');
      socket.emit('action', username, 'connected');
      socket.broadcast.to('room').emit('action', username, 'connected');
    });
    socket.on('message', function(message) {
      socket.emit('message', socket.username, message);
      socket.broadcast.to('room').emit('message', socket.username, message);
    });
});

有没有人知道如何解决这个错误?

【问题讨论】:

    标签: node.js heroku socket.io


    【解决方案1】:

    确保您使用的是 package.json

    中指定的正确版本的 nodenpm
    "engines": {
        "node": "0.8.x"
        ,"npm": "1.1.x"
    }
    

    【讨论】:

    • 非常感谢!我什至不知道您可以指定要使用的 node 和 npm 的版本...
    猜你喜欢
    • 2016-08-08
    • 2023-04-04
    • 1970-01-01
    • 2011-08-28
    • 2013-10-12
    • 1970-01-01
    • 2017-08-19
    • 1970-01-01
    • 2014-01-29
    相关资源
    最近更新 更多