Global Properties for Working with URLs and Sockets

If you are working with URLs, sockets, and processes in your SenseTalk scripts, the following global properties let you change timeout values and cache behavior.

For information about working with URLs and sockets in SenseTalk, see Socket, Process, and Stream Input and Output and URL Transactions and Formatting.

For additional information about working with local and global properties, see Local and Global Properties in SenseTalk.

the URLCacheEnabled Global Property

Values: True, False

Default: True

Behavior: This global property controls whether the contents retrieved from a URL resource can be cached. When set to True (the default), URL contents can be cached by the system and retrieved from the cache rather than being fetched remotely each time. To force a fresh copy of the URL to be loaded, set the URLCacheEnabled property to False before accessing a URL.

Example:

set the URLCacheEnabled to false

Example:

set the URLCacheEnabled to false

put url "http://www.apple.com" into appleHomePage -- Get a fresh copy

set the URLCacheEnabled to true -- Restore caching

the URLTimeout Global Property

Values: A time value, in seconds

Default: 30 seconds

Behavior: This global property specifies the maximum time allowed before a URL resource request times out. If this time limit is exceeded or there is no Internet connection available, or if some other error occurs, the result() function returns an exception object identifying the error, which can be accessed on the next line of the script.

Example:

set the URLTimeout to 45

Example:

set the URLTimeout to 10

put url "http://google.com"

the URLErrorLevel Global Property

Values: An integer

Default: 400

Behavior: This global property value indicates the lowest URL status code that is treated as an error when fetching the contents of a URL. The default value is 400, so a returned status value of 400 or above either throws an exception or sets the result() function to an exception (depending on the current setting of the throwExceptionResults global property). You can set the URLErrorLevel to zero (or to any sufficiently large number) to prevent this type of exception from being generated.

Example:

set the URLErrorLevel to 450

Example:

set the URLErrorLevel to 300

set the throwExceptionResults to false

put url "http://localhost:8080/api/test"

put the result into Problem

if Problem Contains "401" then

log "Unauthorized."

else if Problem Contains "307" then

log "Redirected"

end if

the readTimeout Global Property

Values: A time value, in seconds

Default: 30 seconds

Behavior: This property sets the maximum time a socket read request waits for data to become available. If the socket is unavailable within the time limit, an exception is thrown. If the requested data is not read within the time specified by the readTimeout, whatever has been read is returned and the result() function is set to indicate time out.

Example:

set the readTimeout to 60

Example:

set the readtimeout to 5

open process "skype"

read from process "skype" until end // Tries reading the process for 5 seconds

put the result // Displays 'time oseut'

close process "skype"

Related:

 

This topic was last updated on August 19, 2021, at 03:30:51 PM.

Eggplant icon Eggplantsoftware.com | Documentation Home | User Forums | Support | Copyright © 2022 Eggplant