在 socket.io 上设置高关闭超时是否安全? [英] Is it safe to set a high close timeout on socket.io?

查看:29
本文介绍了在 socket.io 上设置高关闭超时是否安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Web 应用程序,用户需要在其中保持连接.默认情况下,socket.io 会在 60 秒后断开连接.我打开了重新连接",所以它基本上每分钟关闭和重新打开连接.这可能会导致我连接的客户端的提要/通知出现问题.将此超时设置为 10 分钟或更长时间是否安全?现在这么低有什么原因吗?

I have a web application where the user needs to be constantly connected. By default, socket.io will disconnect the connection after 60 seconds. I have 'reconnection' turned on though, so it is essentially closing and reopening the connection every minute. This can cause issues with feeds/notifications to my connected clients. Would it be safe to set this timeout to lets say, 10 minutes, or possibly higher? Is there a reason it is so low right now?

推荐答案

我猜你可能误解了 'close timeout' 配置.它不会导致连接在 60 秒后关闭.(如果客户端不断重新连接,心跳将毫无意义).

My guess is that you may be misinterpreting the 'close timeout' configuration. It does not cause the connection to be closed after 60 seconds. (Heartbeats would be pointless if clients constantly reconnected).

如果客户端断开连接,close timeout 是服务器在释放与该连接关联的资源之前等待的时间.本质上,这允许具有间歇性连接问题的客户端在服务器忘记它们之前尝试重新连接.将 close timeout 设置为十分钟可能是个坏主意,因为它会占用服务器资源.

If a client disconnects, close timeout is the amount of time the server will wait before releasing resources associated with that connection. Essentially, this allows clients with intermittent connectivity issues to attempt to reconnect before the server has forgotten about them. Setting close timeout to ten minutes is probably a bad idea since it will tie up server resources.

如果您的客户实际上每 60 秒断开一次连接,那么就像 samjm 所说的那样,还有其他问题.

If your clients are, in fact, disconnecting every 60 seconds, then, like samjm said, something else is wrong.

这篇关于在 socket.io 上设置高关闭超时是否安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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