且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

确定互联网连接的更好方法

更新时间:2022-02-23 08:13:51

在我们使用 Web 服务的应用程序中,我们实际上采取了两步法.第一步将包括你的技术测试",看看我们是否在理论上启用了网络.如果失败,我们会发出警告消息,例如未检测到网络连接".

In our apps that use web services, we actually take a two step approach. The first step would include your "technical test" to just see if we are network enabled, in theory. If we fail that, we give a warning message like "No network connection detected".

我们要做的第二步是用最少的调用 ping 我们的服务器,看看我们是否可以访问它们.我们是否可以访问网络上的大量网站并不重要,只要我们可以访问我们的网站,所以我们会进行第一次快速调用,如果失败,我们会说无法连接到 siteX.请稍后再试"

The second step we do, is we ping our servers with a minimal call, just to see if we can hit them. It doesn't matter if we can hit a gajillion sites on the web, only if we can hit ours, so we do our first quick call, and if it fails, we say "Can't connect to siteX. Please try again later"