我查看了有关此问题的所有Stack Overflow问题。不过,我无法与Heroku一起运行Socket IO。我查看了https://github.com/socketio/socket.io/issues/1542和https://github.com/nodejs/node-v0.x-archive/wiki/Socket.IO-and-Heroku。套接字在本地运行。
index.js
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var port = process.env.PORT || 8080;
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
io.on('connection', function(socket){
io.set("transports", ["xhr-polling"]);
io.set("polling duration", 10);
});
var server = http.listen(port, function(){
});
正在运行的样本在这里。 https://curly-octo-woof.herokuapp.com/