Author Topic: Is Internet Connection Available?  (Read 10159 times)

0 Members and 1 Guest are viewing this topic.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Is Internet Connection Available?
« Reply #15 on: April 17, 2013, 01:49:34 PM »
Is increasing Delay related to the speed of the Internet Connection.
Yes; Gaston's solution may be better however - very good Gaston.
Partly correct. What you're actually seeing is a delay caused by something called latency. This is the delay between a request sent and an answer received. Not to be confused with baud-rate, which is the amount of data which can be transferred per second.

See it as analogous to the time you wait between dialling a number and the recipient picking up the phone, as opposed to how fast the 2 of you can exchange words once the call is active. Only on the internet, this can be a situation of you dialling to numerous intermediaries to get to your final destination. Some of these might have different connections which require more control signals, which in turn would lengthen the latency. In most cases if a wireless connection happens somewhere the latency increases drastically (wireless tends to have multiple times more control signals than wired), that's usually why something like ADSL is preferred over 3G/HSDPA/LTE when your application needs to perform lots of small requests (like in online gaming), but makes little difference if your application makes one request to download a large file.

I've even had situations where latency is more than 1 second (i.e. set delay to more than 1000) on a mobile connection (i.e. HSDPA), but that same connection has a baud-rate of 4MB/s. While the ADSL's latency to the same server was only 60ms (i.e. a delay of 70 would be more than sufficient), but its baud ran at 256kb/s - less than a 1/10th of the HSDPA's. Though, you cannot compare the 2 directly - one may have more jumps to get to that same server than needed by the other.

The Ping idea is definitely the way to go with this, since it simply waits until an answer is received or a timeout occurs (usually after 5 seconds) - so no need to wait until something happens. This is in fact the testing utility to see if a connection between 2 nodes can be made.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

VovKa

  • Water Moccasin
  • Posts: 1629
  • Ukraine
Re: Is Internet Connection Available?
« Reply #16 on: April 17, 2013, 02:33:11 PM »
Maybe something along the lines of:

Code: [Select]
;; Internet-p  -  Lee Mac
;; Returns T if internet connection is available

(defun LM:internet-p ( / obj rtn url )
    (setq url "http://www.google.com/") ;; url to test
    (if (setq obj (vlax-get-or-create-object "winhttp.winhttprequest.5.1"))
        (progn
            (setq rtn
                (vl-catch-all-apply
                    (function
                        (lambda ( )
                            (vlax-invoke obj 'open "GET" url :vlax-false)
                            (vlax-invoke obj 'send)
                            (command "_.delay" 200) ;; Increase if slow connection
                            (vlax-get obj 'status)
                        )
                    )
                )
            )
            (vlax-release-object obj)
            (if (vl-catch-all-error-p rtn)
                (prompt (vl-catch-all-error-message rtn))
                (= 200 rtn)
            )
        )
    )
)
Lee, you can avoid 'command' by using asynchronous request and setting a timer
Code: [Select]
(lambda ()
   (vlax-invoke obj 'open "GET" url :vlax-true)
   (vlax-invoke obj 'send)
   (vlax-invoke obj 'WaitForResponse 1)
   (vlax-get obj 'status)
)

and www.theswamp.org instead of www.google.com of course :)

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Is Internet Connection Available?
« Reply #17 on: April 17, 2013, 05:57:18 PM »
Lee, you can avoid 'command' by using asynchronous request and setting a timer
Code: [Select]
(lambda ()
   (vlax-invoke obj 'open "GET" url :vlax-true)
   (vlax-invoke obj 'send)
   (vlax-invoke obj 'WaitForResponse 1)
   (vlax-get obj 'status)
)

Thanks VovKa!
That's a far better solution and will also help when writing functions for file download.

and www.theswamp.org instead of www.google.com of course :)

Of course :)


@Irné: fantastic explanation, I like the telephone analogy. :)