Gmail 浏览器客户端如何检测互联网/服务器断开连接(速度和可扩展性)

发布于 2024-11-10 05:13:22 字数 197 浏览 5 评论 0原文

我们有一个浏览器应用程序 (SaaS),我们希望在互联网连接或服务器连接丢失时通知用户。 Gmail 做得非常好,当我拔掉互联网电缆或禁用网络流量时,它立即说无法到达服务器,并给我一个重试倒计时。

实施这样的事情的最佳方法是什么?我是否希望客户端浏览器每秒向应用程序服务器发出 AJAX 请求,或者拥有一个仅报告“活动”的单独服务器。可扩展性将成为未来的一个问题。

We have an browser application (SaaS) where we would like to notify the user in the case of internet connection or server connection loss. Gmail does this very nicely, the moment I unplug the internet cable or disable network traffic it immediately says unable to reach the server and gives me a count down for retry.

What is the best way to implement something like this? Would I want the client browser issuing AJAX requests to the application server every second, or have a separate server that just reports back "alive". Scalability will be come an issue down the road.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不美如何 2024-11-17 05:13:22

由于 GMail 已经每隔几秒检查一次新电子邮件,并且更频繁地检查聊天信息,因此无需单独请求即可判断连接是否已断开。如果您不使用 Ajax 进行其他类型的持续更新,那么是的,您只需让服务器回复某种“活动”信号即可。但请注意,由于 Ajax 跨域限制,您无法使用单独的服务器。

Because GMail already checks for new e-mails every some seconds and for chat information even more frequently, it can tell without a separate request if the connection is down. If you're not using Ajax for some other sort of constant update, then yes, you would just have your server reply with some sort of "alive" signal. Note that you couldn't use a separate server because of Ajax cross-domain restrictions, however.

酷遇一生 2024-11-17 05:13:22

当服务器向客户端报告(通过 Comet 推送)时,您必须为每个客户端维护一个开放的连接。如果您有大量客户,这可能会非常昂贵。正如您提到的,可扩展性可能是一个问题。另一种选择是轮询。您可以让它每 5-10 秒左右轮询一次,而不是每秒执行一次。

您还可以查看 Web Sockets (作为 HTML 5 的一部分开发),但我不确定它是否被广泛支持(据我所知只有 Chrome 支持)。

With the server reporting to the client (push via Comet), you have to maintain an open connection for each client. This can be pretty expensive if you have a large number of clients. Scalability can be an issue, as you mentioned. The other option is to poll. Instead of doing it every second, you can have it poll every 5-10 seconds or so.

Something else that you can look at is Web Sockets (developed as part of HTML 5), but I am not sure if it is widely supported (AFAIK only Chrome supports it).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文