2013-04-09 76 views
1

我在heroku上有一个简单的节点程序,定期向其所有客户端发送消息。但我不断收到下面的警告,导致重新连接。这是我应该担心的吗?我每2-3次都会得到这个结果。heroku上的socket io

请注意,本地主机上没有任何警告或重新连接。我为local和heroku实例使用长轮询配置。另外,我越高,我在Heroku上的PS就越多,这些警告就越多。

错误

warn: client not handshaken client should reconnect 

app.js

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

io.sockets.on('connection', function (socket) { 
    socket.emit('news', 'reconnect'); 
}); 

setInterval(function(){ 
    io.sockets.emit('news', {time: new Date()}) 
},3000); 

client.js

var socket = io.connect('/'); 
socket.on('news', function (data) { 
    console.log(data); 
}); 
+0

我知道这可能听起来有点奇怪,但你有没有试过联系他们的支持? – 2013-04-09 21:28:00

回答

2

此外,较高的I扩展我在Heroku上PS,而以上的这些警告我得到。

是关键。

Socket.io被设计为在单个进程中运行。它将它的会话存储在内存中。你需要你的代理是粘性的,总是把同一个用户发送到同一个进程,或者你需要共享会话(这会更好,因为你共享房间);

的信息是@

​​

短期的是,你需要使用Redis的

var RedisStore = require('socket.io/lib/stores/redis') 
    , redis = require('socket.io/node_modules/redis') 
    , pub = redis.createClient() 
    , sub = redis.createClient() 
    , client = redis.createClient(); 

io.set('store', new RedisStore({ 
    redisPub : pub 
, redisSub : sub 
, redisClient : client 
})); 

幸运的Heroku有五个不同的Redis插件三,其中有免费的层次。