1

I have read some of the articles and knows that you need xhr-polling for socket.io to work on heroku, and this is what I have so far:

var app = require('http').createServer();
var io = require('socket.io').listen(app, {origins: '*:*'});

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

io.sockets.on('connection', function(socket) {
        console.log("Connected...");
        socket.on('message', function(message) {
        console.log("Message in:" + message.toString());
    }
}

This code sometimes works, sometimes it stop at console.log("Connected...") and won't go into socket.on('message', function(message). I have no idea why it only works whenever it feels like it. I have also tried restart the app but still not working.

4

1 に答える 1

1

トランスポートの設定に加えて、xhr-pollingポーリング期間も設定する必要があります

io.set("polling duration", 10);

于 2012-06-14T18:19:40.023 に答える