How to check internet connection without error message?

Questions about GP commands and how to do things

Moderator: MSandro

Post Reply
MSandro
Posts: 162
Joined: Jul 26th, '17, 21:12

How to check internet connection without error message?

Post by MSandro » Mar 31st, '18, 13:30

Hi, I am working on a project which should access some files in the internet, so I would like to have a sort of "connection-test" to prevent the "unknown host" error to appear. How could I do that?

Thank you very much.

User avatar
Calloway
Posts: 100
Joined: Apr 30th, '18, 00:28
Location: Eastern United States

Re: How to check internet connection without error message?

Post by Calloway » Jul 20th, '18, 18:00

Using an if-else maybe?... I don't know, you could try using cloud variables?

JohnM
Posts: 379
Joined: Sep 11th, '15, 14:42

Re: How to check internet connection without error message?

Post by JohnM » Jul 22nd, '18, 21:21

Check out the "safelyRun" function in tasks.gp.

That will allow you to try to open a socket to a given host. If you provide an error function, it will be called if the attempt fails. Or, if you don't provide an error function, you'll get a Task object back if it fails or an ExternalReference back if it succeeds. So you can check the class of the returned value to figure out what happened.

Post Reply