如何检查我是否确实已连接到互联网 [英] How can I check I am actually connected to the internet

查看:93
本文介绍了如何检查我是否确实已连接到互联网的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Indy连接到Ftp服务器。我们遇到了服务器宕机的问题,并创建了一个找不到主机错误,我已处理并向用户指示该错误,但是今天,该软件已安装在没有Internet连接的计算机上。当我连接时产生的错误也是找不到主机,这不是完全正确的。是否可以在TIdFtp组件内部调用某个函数/过程,该函数/过程会告诉我是否确实存在与Internet的连接,所以我可以显示错误消息,指示用户未连接?我正在使用Delphi XE Seattle。



我已经浏览了IdFtp属性/函数等列表,但似乎没有什么明显的东西。 class = h2_lin>解决方案


我可以在TIdFtp组件内部调用一个函数/过程来告诉我是否确实存在与互联网的连接,所以我可以显示一个错误,指示用户未连接?


否。您需要做的是尝试与多个不同的服务器建立TCP连接,并查看其中的任何一个是否成功或全部失败。例如,您可以使用 TIdTCPClient 连接到众所周知的服务器端口,这些端口几乎可以保证99%以上的时间都处于联机状态,例如 google.com / yahoo.com 在端口80(HTTP)或443(HTTPS)等上。


I am using Indy to connect to an Ftp server. We have had problems with the server being down, creating a "Host not found" error, which I handle and indicate to the user, however, today the software was installed on a computer that did not have an internet connection. The error produced when I "Connect" is also "Host not found", which is not totally correct. Is there a function/procedure I can call inside the TIdFtp component that will tell me if there is actually a connection to the internet so I can display an error indicating the user is not connected? I am using Delphi XE Seattle.

I have looked through the list of IdFtp properties/functions etc, but nothing seems obvious.

解决方案

Is there a function/procedure I can call inside the TIdFtp component that will tell me if there is actually a connection to the internet so I can display an error indicating the user is not connected?

No. What you will have to do is attempt a TCP connection to several different servers and see if any of them succeed or if they all fail. For instance, you can use TIdTCPClient to connect to well-known server ports that are pretty much guaranteed to be online 99+% of the time, like google.com/yahoo.com on port 80 (HTTP) or 443 (HTTPS), etc.

这篇关于如何检查我是否确实已连接到互联网的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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