Announcement

Collapse
No announcement yet.

Callback functions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Callback functions

    Was playing around with 'callback functions' tonight, and stumbled across an old project of mine from some time back (different incarnation, LOL). It's one of my favorites, so decided to make a few minor tweaks / improvements, to offer it up again as an example of using of callback-functions to define behavior in the Progress Object whilst syncing transfer-statistics on the HTTP.Download command.

    So basically, this is an HTTP downloader (which although only single-threaded) will download an infinite series of files, sequentially. And show the progress and transfer-stats on each sequential download. It's pretty basic as far as downloaders go. But maybe someone here is 'cluey' enough to build upon the concept and make it into a 'true' file downloader by incorporating 'multi-threading'. I know for example, that Reteset's Multi-threaded Download Plugin can make this achievable - but all that's a bit 'beyond my pay-grade' at this stage.

    Anyway, I'll leave it here for anyone interested in taking a look-see, yeah? Code's nice and clearly 'commented' - so easy to follow. Hope someone finds it helpful.
    Attached Files

  • #2
    To check connection do not use
    IsConnected = HTTP.TestConnection("http://www.google.com", 20, 80, nil, nil);
    but use
    cnct = HTTP.GetConnectionState();
    if cnct.Connected==true then

    Comment


    • #3
      like that
      Code:
      -- Ensures user has established internet-connection before attempting to use application
      --Dialog.SplashFlash("AutoPlay\\Flash\\loader.swf", 3, false);
      cnct = HTTP.GetConnectionState();
      if cnct.Connected==true then
       Page.Jump("Page2");        
          else
           Paragraph.SetText("Paragraph1", "No Internet Connection Detected.\r\nEnsure you're connected and try again.");            
              -- Image object properties table.
               tblImageProps = {};
               tblImageProps.Height = 95;
               tblImageProps.Width = 98;
               tblImageProps.Y = 75;
               tblImageProps.X = 200;         
               Image.SetProperties("Image1", tblImageProps);
               Image.Load("Image1", "AutoPlay\\Images\\logo2.png");
      end

      Comment


      • #4
        Care to explain why? User manual has this to say on each method:

        HTTP.GetConnectionState
        Note: You cannot rely solely on the fact that the Connected result of HTTP.GetConnectionState returning true means that you have a valid active Internet connection. It is impossible for HTTP.GetConnectionState to determine if the entire connection to the Internet is functioning without sending a request to a server. This is why you need to send a request to determine if you are really connected or not.

        HTTP.TestConnection
        Note: The default proxy settings that are currently configured through Internet Explorer will be used for testing the connection by default, and is the recommended method. However if you require alternate proxy settings, they can be passed through the ProxyData parameter.
        So, I'm not quite following your reasoning. Can you elaborate a bit on why you think it's a better method?

        Comment


        • #5
          HTTP.GetConnectionState check the internet connection only HTTP.TestConnection check the server ready state so what is the point in cheking google server in your code ?? we do not need any sever or page check HTTP.GetConnectionState is 100 time faster it is about speed man

          Comment


          • #6
            the difference between
            HTTP.GetConnectionState and HTTP.TestConnection
            is the difference between "instance" and "please wait"

            Comment


            • #7
              Again, from the manual (paying particular attention to the parts highlighted in red):

              HTTP.GetConnectionState
              Note: You cannot rely solely on the fact that the Connected result of HTTP.GetConnectionState returning true means that you have a valid active Internet connection. It is impossible for HTTP.GetConnectionState to determine if the entire connection to the Internet is functioning without sending a request to a server. This is why you need to send a request to determine if you are really connected or not.
              HTTP.TestConnection
              Note: The default proxy settings that are currently configured through Internet Explorer will be used for testing the connection by default, and is the recommended method.
              So, I ask again - what is your logic? ('Faster' does not trump 'reliability' or basic good coding practice).
              But I thank you for your input, nevertheless. Keep the faith, brother.

              Comment


              • #8
                reliability ?? forgot about the manual because its point in unclear for you in few words HTTP.GetConnectionState is for pages HTTP.TestConnection is for the internet connection just give a try

                Comment


                • #9
                  why not do both save everyone a headache lmao.

                  Comment


                  • #10
                    test if the faster method returns false and if so .. then do the slower google route.

                    Comment


                    • #11
                      Originally posted by BioHazard View Post
                      Was playing around with 'callback functions' tonight, and stumbled across an old project of mine from some time back (different incarnation, LOL). It's one of my favorites, so decided to make a few minor tweaks / improvements, to offer it up again as an example of using of callback-functions to define behavior in the Progress Object whilst syncing transfer-statistics on the HTTP.Download command.

                      So basically, this is an HTTP downloader (which although only single-threaded) will download an infinite series of files, sequentially. And show the progress and transfer-stats on each sequential download. It's pretty basic as far as downloaders go. But maybe someone here is 'cluey' enough to build upon the concept and make it into a 'true' file downloader by incorporating 'multi-threading'. I know for example, that Reteset's Multi-threaded Download Plugin can make this achievable - but all that's a bit 'beyond my pay-grade' at this stage.

                      Anyway, I'll leave it here for anyone interested in taking a look-see, yeah? Code's nice and clearly 'commented' - so easy to follow. Hope someone finds it helpful.
                      must admit that , that is a very good .apz there BioHazard. Good Work Mate

                      Comment


                      • #12
                        where does this function come from?

                        local strkbs = string.format("%.1f", TransferRate);

                        Comment


                        • #13
                          Originally posted by curious1 View Post
                          where does this function come from?

                          local strkbs = string.format("%.1f", TransferRate);
                          Local variable for displaying the download-speed, eh? Whereby "%.1f" represents a floating-point number with one digit after the decimal point. eg. 950.8 KB/S

                          It comes from the String Library over at Lua.org: https://www.lua.org/pil/20.html

                          Thank fcuk this thread didn't devolve into a debate on checking internet-connection status. The title is "Callback functions" after all. Thanks for your interest, curious1.

                          Comment


                          • #14
                            Interesting! , i was asking because I could not find string.format in the manual , but thanks for clearing that up for me
                            and no problemo , I was actually supposed to add this very type of thing into a project I was working on recently. I like the clean approach and all the stats/figgures/Information
                            displayed with this. Also very few lines of code which is always good.

                            Comment


                            • #15
                              Originally posted by BioHazard View Post
                              devolve into a debate on checking internet-connection status.
                              sorry if my remarks bothering you.
                              promise to keep away in future.
                              thanks for your patience.

                              Comment

                              Working...
                              X