How can I check I am actually connected to the internet

限于喜欢 提交于 2019-12-13 03:08:44

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/57213954/how-can-i-check-i-am-actually-connected-to-the-internet

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!