Source language: Translate to:

InternetFileExists

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

InternetFileExists

Postby domino » Fri Jan 20, 2006 12:49 pm

Today my ISP suffered a major power failure which resulted in some files associated with my NB application not being available for a number of hours.

In the startup actions I have a block of code similar to this....

InternetFileExists "www.yoursite.com/sample.txt" "[Result]"
If "[Result]" "=" "True"
AlertBox "Status" "The file was found!"
EndIf

Unfortunately this resulted in the app freezing instead of returning [False].

Could anyone sugest some code I could use to limit the time that the app takes to return a result and continue with the program flow... ie some sort of timeout condition.

(For info when the server is operating normally... if the user isn`t connected to the Internet there isn`t a problem.. it just returns [False])

Cheers
Dave
User avatar
domino
 
Posts: 275
Joined: Sat Apr 02, 2005 7:11 am
Location: Notts UK

Postby Jay-Bird » Sat Jan 21, 2006 11:49 am

InternetFileExists "www.yoursite.com/sample.txt" "[Result]"
If "[Result]" "=" "True"
AlertBox "Status" "The file was found!"
EndIf

If "[Result]" "=" "False"
AlertBox "Status" "The file was NOT found!"
EndIf

I think I remember having to give a script direction for both conditions or you get the freeze...or you could use If "[Result]" "<>" "True"...also you may have to use the ELSE and include the "False" in the second condition, instead of above:

InternetFileExists "www.yoursite.com/sample.txt" "[Result]"
If "[Result]" "=" "True"
AlertBox "Status" "The file was found!"
Else
AlertBox "Status" "The file was NOT found!"
EndIf
...I do remember having the freeze up in first coding this app

Here is some sample code from a pub I created a while back to keep an eye on and log files from my servers...so far it works great when the file is not found.(txtURL1 is a text entry box for a file on a server)

Code: Select all
...check for file
If "[inetFileExists]" "=" "False"
        Delay "15000"...delay 15 seconds and try again
           InternetFileExists "[txtURL1]" "[inetFileExists]"
              If "[inetFileExists]" "=" "False"
              SetVar "[ExistResult]" "DOWN"
              FileWrite "log1.log" "Append" "Check Interval : [txtMinutes]-------Result at [DateShort], {[Hour]:[Minute]}-------{[ExistResult]}"
            Else
             SetVar "[ExistResult]" "OK"
             FileWrite "log1.log" "Append" "Check Interval : [txtMinutes]-------Result at [DateShort], {[Hour]:[Minute]}-------{[ExistResult]}"
            EndIf

Else ....found the file so write OK to the log
 SetVar "[ExistResult]" "OK"
 FileWrite "log1.log" "Append" "Check Interval : [txtMinutes]-------Result at [DateShort], {[Hour]:[Minute]}-------{[ExistResult]}"
EndIf


....Sorry, I noticed the code is getting wrapped..I hope you can make sense of it
Maybe this will help....if it is not clear what I am doing, let me know and I will post more
User avatar
Jay-Bird
 
Posts: 164
Joined: Fri Apr 01, 2005 7:01 am
Location: Louisiana , USA

Postby domino » Sat Jan 21, 2006 1:50 pm

Thanks Jaybird

I see exactly what you're saying and am creating a few routines to try it all out and report back, but it is very difficult to test because I can`t know when the Webserver is not available. (ie Valid URL, IP etc)

On a wider note this NB/Internet area in general is still causing me a couple of headaches...I`ve been using
Code: Select all
FileExists
to confirm the user is actually online.

Case 1: Is user connected to the Internet?
Code: Select all
CheckInternetConnection
Returns True if Local Network Connection active - even if no Internet Connection available.

Case 2: Does File Exist?
Code: Select all
FileExists
Works correctly if file does or does not exist, or even if the URL doesn`t exist. But (as we are discussing) causes a freeze up if the Webserver is not available.

I also seem to remember that filedownload causes a freeze if the server is temporarily unavailable..(No problem if the file doesn`t exist) In fact I have a routine Gaev posted a while back to try and deal with this albeit in a slightly different context .

I appreciate it isn`t possible to write an action command to cater for every eventuality, but especially in these days of shared hosting accounts some sort of timeout option would be really handy to prevent freeze ups.

Cheers
Dave
User avatar
domino
 
Posts: 275
Joined: Sat Apr 02, 2005 7:11 am
Location: Notts UK

Postby Jay-Bird » Sat Jan 21, 2006 2:03 pm

About the user being connected, I am familiar with the problem..I coded timers to check internet connection (local) and then a file exists for the actual connection to the "Internet"...it's a workaround that works in my unique situation.

I agree that a "Timeout" option would be nice... maybe a second parameter in the NB Command, possibly:

Code: Select all
InternetFileExists "http://www.whatever.com/test.txt" "[result]" "15000" "AlertBox "Not Found" "File not found!""

(Notice addition of Timeout-15000 and Another Command-Message Box)

Instead of:

InternetFileExists "http://www.whatever.com/test.txt" "[result]"


I'll keep my thinking cap on ... perhaps we should post this in Suggestions?
User avatar
Jay-Bird
 
Posts: 164
Joined: Fri Apr 01, 2005 7:01 am
Location: Louisiana , USA

Postby domino » Sat Jan 21, 2006 4:38 pm

About the user being connected, I am familiar with the problem..I coded timers to check internet connection (local) and then a file exists for the actual connection to the "Internet"...it's a workaround that works in my unique situation.


Yes that's what I`ve been doing in effect.... Talking to colleagues it seems that the Shared Hosting Servers tend to be subject to brief but frequent losses of service. This isn`t a Neosoft problem of course... but there has to be a way to stop the app freezing on these occasions.

I agree that a "Timeout" option would be nice... maybe a second parameter in the NB Command, possibly:


That would be perfect...

Cheers
Dave
User avatar
domino
 
Posts: 275
Joined: Sat Apr 02, 2005 7:11 am
Location: Notts UK

Postby Gaev » Sat Jan 21, 2006 6:36 pm

Any suggested workarounds will be hard to test ... where's a crashed server when you need one !! ... however, assuming that IE does not crash under similar circumstances, you might consider ....
Code: Select all
TimerStart "Timer1" "[UserThresholdOfPain]"
BrowserGoTo "WebBrowser1" "www.my_unreliable_website.com/are_you_there.php?now=ccyymmdd_hhmmss"
... and in the Navigate Complete section of your Browser object, you ...
Code: Select all
TimerStop "Timer1"
BrowserExport "WebBrowser1" "[ReceivedData]"
... other code to check [ReceivedData] and confirm site is up
SetVar "[SiteStatus]" "Up"
... and for the TimerEvent section ...
Code: Select all
BrowserStop "WebBrowser1"
SetVar "[SiteStatus]" "Down"
AlertBox "Dang" "Website is down ... again !"


Then, [SiteStatus] should guide you to continue/not.
User avatar
Gaev
 
Posts: 3716
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby domino » Sun Jan 22, 2006 4:13 am

however, assuming that IE does not crash under similar circumstances, you might consider ....


Interesting idea.....

where's a crashed server when you need one !!


Hopefully on my spare PC later today... I`m setting up a Linux/Apache webserver on my Local network to try and create a controllable test environment to try these workarounds.

Cheers
Dave
User avatar
domino
 
Posts: 275
Joined: Sat Apr 02, 2005 7:11 am
Location: Notts UK

Postby Jay-Bird » Sun Jan 22, 2006 7:12 am

Thats a switch...now we NEED a crashed server...hehehe

Thanks for the tickle this morning.. I needed it :D
User avatar
Jay-Bird
 
Posts: 164
Joined: Fri Apr 01, 2005 7:01 am
Location: Louisiana , USA

Postby domino » Sun Jan 22, 2006 5:05 pm

where's a crashed server when you need one !!

...On my other PC!...

Quite a useful exercise actually...

Simulating the Webserver Down scenario does Freeze the PC, but correctly returns a [False] result after approx 90 seconds. (I`ve never waited that long before.. but it's approx 90 seconds every time I tried it)

What seems to be happening is the same effect as when you try to navigate to an unavailable webpage and end up with Page Not Found.

The difference is that you can bail out .. and the Browser (lack of)progress bar gives you the clue.

Using Gaevs idea the browser doesn`t crash and the timer can be set to do the job [UserThresholdOfPain] .....

However I still think there is a good case for a timeout option if this is possible. 2 seconds perhaps...

Cheers
Dave
User avatar
domino
 
Posts: 275
Joined: Sat Apr 02, 2005 7:11 am
Location: Notts UK

Postby Gaev » Sun Jan 22, 2006 10:27 pm

Dave:
However I still think there is a good case for a timeout option if this is possible. 2 seconds perhaps...
If the Browser Control 9deployed by NeoBook) provides TimeOut facilities, yes it would be a nice feature to add to this function ... but perhaps ...

a) as a developer defined value ... even with my high speed access, I have had reason to wait for responses from some sites that are painfully long
b) as a new command/variable ... so as not to break existing applications ... e.g. ..

InternetFileExistsTimeOut "timeout in milliseconds"
or
SetVar "[InternetFileExistsTimeOut]" "timeout in milliseconds"

... and the absence of this command/variable would mean "no timeout" (as now).
User avatar
Gaev
 
Posts: 3716
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby Neosoft Support » Mon Jan 23, 2006 1:01 pm

I'm not sure if the Windows API functions NeoBook uses offer a time out option, but I'll see if there's anything we can do.
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5593
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA

Postby Gaev » Thu Jan 26, 2006 12:25 pm

Dave (domino):

Another possible solution ... Ping the website BEFORE performing any file related functions.

You might first verify that this command does not hang/crash your PC when the site is down ... using the command from DOS.
Code: Select all
Usage: ping [-t] [-a] [-n count] [-l size] [-f] [-i TTL] [-v TOS]
            [-r count] [-s count] [[-j host-list] | [-k host-list]]
            [-w timeout] destination-list

Options:
    -t             Ping the specified host until stopped.
                   To see statistics and continue - type Control-Break;
                   To stop - type Control-C.
    -a             Resolve addresses to hostnames.
    -n count       Number of echo requests to send.
    -l size        Send buffer size.
    -f             Set Don't Fragment flag in packet.
    -i TTL         Time To Live.
    -v TOS         Type Of Service.
    -r count       Record route for count hops.
    -s count       Timestamp for count hops.
    -j host-list   Loose source route along host-list.
    -k host-list   Strict source route along host-list.
    -w timeout     Timeout in milliseconds to wait for each reply.
If it works, you might also consider using the same facility in AutoIt ...
Code: Select all
Ping ( address or hostname [, timeout] )

address/hostname    Can be i.e. "www.hiddensoft.com" or "178.50.76.4".
timeout [optional]  Is the time to wait for an answer in milliseconds (default is 4000).

Return Value

Success: Returns the roundtrip-time in milliseconds ( greater than 0 ).
Failure: Returns 0 if host is not pingable or other network errors occured and sets @error. (See Remarks)

Remarks

When the function fails (returns 0) @error contains extended information:
 1 = Host is offline
 2 = Host is unreachable
 3 = Bad destination
 4 = Other errors

Example
$var = Ping("www.hiddensoft.com",250)


And if (attempting to) ping does not hang/crash the client machine, perhaps NeoBook could provide a similar function e.g. ...
Code: Select all
InetPing "website address" "timeout" "[PingResult]"
or
InetHostStatus "website address" "timeout" "[Status]"
User avatar
Gaev
 
Posts: 3716
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby Neosoft Support » Thu Jan 26, 2006 4:01 pm

And if (attempting to) ping does not hang/crash the client machine, perhaps NeoBook could provide a similar function e.g. ...
Code:
InetPing "website address" "timeout" "[PingResult]"
or
InetHostStatus "website address" "timeout" "[Status]"


Good suggestion! I'll add it to the list.
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5593
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA

Postby domino » Fri Jan 27, 2006 2:54 am

Gaev.. Support

Thanks for the feedback on this.

I had another embarrasing "brief loss of server event" yesterday during a commercially important 1-2-1 demo.

Clearly the state of my ISP is not an NB problem and changing ISP's is something I am considering, but in the context we're discussing here an event that would be nothing out of the ordinary in a users Web Browser is seen as the application not working as it should because of the albeit temporary "freeze." Slow loading Webpages are also an issue in this context.

Gaevs idea of using Ping is something I`d thought about in the past and the idea/code presented is something I`m looking at today ... also I`m giving more thought to user clues like "Loading.. Please wait" type messages.

Cheers
Dave
User avatar
domino
 
Posts: 275
Joined: Sat Apr 02, 2005 7:11 am
Location: Notts UK

Postby Jay-Bird » Fri Jan 27, 2006 8:56 am

I second a vote for:

InetPing "website address" "timeout" "[PingResult]"

That would be handy in lots of other cases also...very useful, very useful indeed (scratches beard and wanders into the imagination).....
User avatar
Jay-Bird
 
Posts: 164
Joined: Fri Apr 01, 2005 7:01 am
Location: Louisiana , USA

Next

Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 2 guests