Mastering TS Net

andrew at midwestcoastmedia.com andrew at midwestcoastmedia.com
Mon Jul 2 12:53:34 EDT 2018


Like Jacque mentioned, I don't think you need to bother with tsNet for  
local files since they should be almost instantly loaded.

I too struggled with tsNet when I first tried to implement it, but  
this website helped me more than the LiveCode pages:  
https://www.techstrategies.com.au/tsnet-resources/

The problem you are encountering is that you can only have one unique  
ID referenced at a time (first parameter). If you try to make another  
call using that ID before the first call is returned then you'll get  
an error. Once a call with the ID has been finished (successful or  
not), that ID is recycled and available for use again.

The documentation doesn't explain well (in my initial understanding)  
that this doesn't have to be "1" or even a number. I experimented with  
random(10000) as my pID before encountering that same "ID already in  
use" error and discovered that for most of my uses I could just  
hard-code a text based ID that made more sense to me when  
troubleshooting like "get new image" or "check for updates" or even  
some variable with a unique value (like your tFileName).

--Andrew Bell


> Date: Sun, 1 Jul 2018 15:19:34 +0000
> From: Sannyasin Brahmanathaswami <brahma at hindu.org>
> To: How LiveCode <use-livecode at lists.runrev.com>
> Subject: Mastering TS Net
> Message-ID: <C6F79403-FF07-419F-B3A0-02DFA04847D6 at hindu.org>
> Content-Type: text/plain; charset="utf-8"
>
> I really need to get my head around TSNet, so began experiments.
>
> This is the documentation for tsNetGetFile
>
> " local tHeaders, tResult
>
> put tsNetGetFile("1", "/path/to/downloaded/file.dat", \
> "ftp://user:pass@ftp.example.com/file.dat", tHeaders, \
> "transferComplete") into tResult
>
> on transferComplete pID, pResult, pBytes, pCurlCode
> 	local tData, tHeaders
> 	if pCurlCode is not 0 then
> 		answer tsNetRetrError(pID)
> 	else
> 	a	nswer "File has been downloaded"
> 	end if
> 	tsNetCloseConn pID
> end transferComplete
>
> # but my first attempt to "get it" ... ran into this error.
>
> Are there any good lessons on all TSNet functions?
>  I am not looking forward to wading into this blind as a bat.
>
> # variable watcher
>
> tResult      --        tsneterr: ID already in use
>
> what is strange is this, the IDE gives the error even before tracing  
> the mouseup.
>
> So I did not even get off home plate.
>
> ############
> local tHeaders, tResult
>
> on mouseup
> # put a break here... the IDE show an error *before* stepping into  
> the next statement
> # I can't even close the connection with:
>    tsNetCloseConn "1"
>    put empty into tResult
>    put fld aURL into pURL
>    put empty into fld "fldHTTPHeader"
>    put empty  into fld "tHTMLfield"
>    set the itemDel to "/"
>    put item -1 of pURL into tFileName
>    put ("~/Desktop/"&tFileName) into tLocalFile
>    put tsNetGetFile("1",tLocalFile,pURL,tHeaders,"transferComplete")  
> into tResult
>
>    --  put libURLLastHTTPHeaders() into fld "fldHTTPHeader"
> end mouseup
>
> on transferComplete pID, pResult, pBytes, pCurlCode
>    if pCurlCode is not 0 then
>       answer tsNetRetrError(pID)
>    else
>       answer "File has been downloaded"
>       put tHeaders into fld "fldHTTPHeader"
>    end if
>    tsNetCloseConn pID
> end transferComplete
>
> BR
>
>
> Date: Sun, 01 Jul 2018 13:00:44 -0500
> From: "J. Landman Gay" <jacque at hyperactivesw.com>
> To: How to use LiveCode <use-livecode at lists.runrev.com>
> Subject: Re: Mastering TS Net
> Message-ID:
> 	<16457010ce0.285b.5e131b4e58299f54a9f0b9c05d4f07f9 at hyperactivesw.com>
> Content-Type: text/plain; format=flowed; charset="us-ascii"
>
> Does TSNet even work with local files? For local files use the read/write
> commands or "get/put url".
>
> With a commercial license you shouldn't need to deal with the lower level
> functions for internet communication. The basic put, post, and get commands
> should do it.
>
> --
> Jacqueline Landman Gay | jacque at hyperactivesw.com
> HyperActive Software | http://www.hyperactivesw.com
> On July 1, 2018 10:21:38 AM Sannyasin Brahmanathaswami via use-livecode
> <use-livecode at lists.runrev.com> wrote:
>
>>
>> tResult      --        tsneterr: ID already in use
>>
>> what is strange is this, the IDE gives the error even before tracing the
>> mouseup.
>>
>> So I did not even get off home plate.
>>
>> ############
>> local tHeaders, tResult
>>
>> on mouseup
>> # put a break here... the IDE show an error *before* stepping into the next
>> statement
>> # I can't even close the connection with:
>>   tsNetCloseConn "1"
>>   put empty into tResult
>>   put fld aURL into pURL
>>   put empty into fld "fldHTTPHeader"
>>   put empty  into fld "tHTMLfield"
>>   set the itemDel to "/"
>>   put item -1 of pURL into tFileName
>>   put ("~/Desktop/"&tFileName) into tLocalFile
>>   put tsNetGetFile("1",tLocalFile,pURL,tHeaders,"transferComplete")  
>> into tResult
>>
>>   --  put libURLLastHTTPHeaders() into fld "fldHTTPHeader"
>> end mouseup
>>
>> on transferComplete pID, pResult, pBytes, pCurlCode
>>   if pCurlCode is not 0 then
>>      answer tsNetRetrError(pID)
>>   else
>>      answer "File has been downloaded"
>>      put tHeaders into fld "fldHTTPHeader"
>>   end if
>>   tsNetCloseConn pID
>> end transferComplete
>>
>> BR
>>
>>
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
>
>
> ------------------------------
>
> Message: 8
> Date: Mon, 2 Jul 2018 11:40:13 +1000
> From: Charles Warwick <charles at techstrategies.com.au>
> To: How to use LiveCode <use-livecode at lists.runrev.com>
> Subject: Re: Mastering TS Net
> Message-ID:
> 	<EDA5723B-6AE3-4F5B-863E-7B9A03443FB9 at techstrategies.com.au>
> Content-Type: text/plain;	charset=utf-8
>
> Hi BR,
>
> There are a series of lessons on tsNet on the LiveCode website:
>
> http://lessons.livecode.com/m/4071/c/235433
>
> If you are looking for an example of how to download something  
> direct to a file, the lesson called ?How to asynchronously download  
> via SFTP directly a file? should help.
>
> The same concepts apply for downloading to a file regardless of the  
> protocol being used.
>
> If you can?t quite find an example lesson that answers what you  
> need, let me know and I will get one organised.
>
> Regards,
>
> Charles
>
>> On 2 Jul 2018, at 1:19 am, Sannyasin Brahmanathaswami via  
>> use-livecode <use-livecode at lists.runrev.com> wrote:
>>
>> I really need to get my head around TSNet, so began experiments.
>>
>> This is the documentation for tsNetGetFile
>>
>> " local tHeaders, tResult
>>
>> put tsNetGetFile("1", "/path/to/downloaded/file.dat", \
>> "ftp://user:pass@ftp.example.com/file.dat", tHeaders, \
>> "transferComplete") into tResult
>>
>> on transferComplete pID, pResult, pBytes, pCurlCode
>>    local tData, tHeaders
>>    if pCurlCode is not 0 then
>>        answer tsNetRetrError(pID)
>>    else
>>    a    nswer "File has been downloaded"
>>    end if
>>    tsNetCloseConn pID
>> end transferComplete
>>
>> # but my first attempt to "get it" ... ran into this error.
>>
>> Are there any good lessons on all TSNet functions?
>> I am not looking forward to wading into this blind as a bat.
>>
>> # variable watcher
>>
>> tResult      --        tsneterr: ID already in use
>>
>> what is strange is this, the IDE gives the error even before  
>> tracing the mouseup.
>>
>> So I did not even get off home plate.
>>
>> ############
>> local tHeaders, tResult
>>
>> on mouseup
>> # put a break here... the IDE show an error *before* stepping into  
>> the next statement
>> # I can't even close the connection with:
>>   tsNetCloseConn "1"
>>   put empty into tResult
>>   put fld aURL into pURL
>>   put empty into fld "fldHTTPHeader"
>>   put empty  into fld "tHTMLfield"
>>   set the itemDel to "/"
>>   put item -1 of pURL into tFileName
>>   put ("~/Desktop/"&tFileName) into tLocalFile
>>   put tsNetGetFile("1",tLocalFile,pURL,tHeaders,"transferComplete")  
>> into tResult
>>
>>   --  put libURLLastHTTPHeaders() into fld "fldHTTPHeader"
>> end mouseup
>>
>> on transferComplete pID, pResult, pBytes, pCurlCode
>>   if pCurlCode is not 0 then
>>      answer tsNetRetrError(pID)
>>   else
>>      answer "File has been downloaded"
>>      put tHeaders into fld "fldHTTPHeader"
>>   end if
>>   tsNetCloseConn pID
>> end transferComplete
>>
>> BR
>>
>>
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your  
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>
>
>
>
> ------------------------------
>
> Message: 9
> Date: Mon, 2 Jul 2018 00:45:43 -0400
> From: "Ralph DiMola" <rdimola at evergreeninfo.net>
> To: "'How to use LiveCode'" <use-livecode at lists.runrev.com>
> Subject: RE: Sort IP List
> Message-ID: <000001d411bf$8bc3aeb0$a34b0c10$@net>
> Content-Type: text/plain;	charset="us-ascii"
>
> I agree "mind-bogglingly nonsensical"
>
> Something is very odd. If I open the stack with fresh start of the IDE I
> start getting results closer to what I would expect. The by ref is about 5
> to 10% faster. NOW.... Every so often when I open the message box things
> start getting weird and I get those crazy results. If I close msg then it is
> different weird. When I say different I mean that another step in the
> process starts taking longer. Close LC and restart and things are back to
> normal until I open the message box a few times. No pattern as of yet. But I
> do know if you don't open the message box it never goes crazy. I'm going to
> dig in and see what's happening here. If I can get a recipe I'm going to
> send it off to Panos.
>
> Win 10 VM
> LC 9
>
> Ralph DiMola
> IT Director
> Evergreen Information Services
> rdimola at evergreeninfo.net
>
> -----Original Message-----
> From: use-livecode [mailto:use-livecode-bounces at lists.runrev.com] On Behalf
> Of Mark Wieder via use-livecode
> Sent: Saturday, June 30, 2018 11:05 PM
> To: Ralph DiMola via use-livecode
> Cc: Mark Wieder
> Subject: Re: Sort IP List
>
> Ralph-
>
> Not that I'm doubting your findings, but those both seem mind-bogglingly
> nonsensical to me. Can you post your test code?
>
> --
>   Mark Wieder
>   ahsoftware at gmail.com
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
> ------------------------------
>
> End of use-livecode Digest, Vol 178, Issue 2
> ********************************************







More information about the use-livecode mailing list