触发断开事件之前,Socket.io需要很长时间 [英] Socket.io takes a long time before triggering the disconnect event

查看:182
本文介绍了触发断开事件之前,Socket.io需要很长时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用node.js和socket.io做一个HTML5游戏。我决定将它放在 Heroku上的Socket-io



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

以前,我只使用网络套接字

  io.set(transports,[websocket]); 

现在,当客户端断开连接(关闭窗口或刷新页面)时,事件disconnectisn (它看起来像在等待客户端心跳超时)。

  client.on(在服务器上立即触发) disconnect,onClientDisconnect); 

如果客户端重新加载,我会在断开连接之前接收多个连接事件
我的问题在这里。



你有什么想法,为什么xhr-polling不会触发断开事件?
这是socket.io的一个错误配置吗?



谢谢。

解决方案

它说此处,您可以配置心跳。要正确配置它,您必须在服务器和客户端调整心跳(这是给出的 here )。



尝试降低心跳。它可以解决你的问题。
在其他说明中,appfog似乎支持websocket。


I'm doing an HTML5 Game using node.js and socket.io

I decided to host it on Heroku.

Heroku isn't allowing the use of WebSockets, so I have to setup xhr-polling instead. (Socket-io on Heroku)

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

Before, I was using web-sockets only

io.set( "transports", ["websocket"] );

Now, when a client disconnect (close his window or refresh his page) the event "disconnect" isn't trigger immediatly on the server (it looks like it's waiting for the client heartbeat to time out).

client.on( "disconnect", onClientDisconnect );

If the client reloads, I get multiple connection events before disconnect is fired. My problem is here.

Do you have any ideas, why xhr-polling doesn't fire the disconnect event ? Is this a bad configuration of socket.io ?

Thanks.

解决方案

It says here that you can configure the heartbeat. To properly configure it, you must adjust the heartbeat both on the server and the client side (which is given here).

Try lowering the heartbeat. It may solve your problem. On other note, appfog seems to support websockets.

这篇关于触发断开事件之前,Socket.io需要很长时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆