How to clear the socket cache.

If you find an issue in LiveCode but are having difficulty pinning down a reliable recipe or want to sanity-check your findings with others, this is the place.

Please have one thread per issue, and try to summarize the issue concisely in the thread title so others can find related issues here.

Moderator: Klaus

Post Reply
lilRalph
Posts: 25
Joined: Wed Aug 26, 2015 9:43 am

How to clear the socket cache.

Post by lilRalph » Wed Sep 02, 2015 10:19 am

Sample URL Access.livecode.zip
Simple stack
(2.54 KiB) Downloaded 211 times
Hi folks, I am trying to build an app to put posts on my Wordpress sites.
I would like to do this with LiveCode because of the multi-platform capability.

Part of this is the requirement to login to the site and navigate to the posts part of the dashboard.
To stay logged in to Wordpress it is essential to manage the cookies and follow redirects.

I have done this using Python, Phantomjs, Pure Basic and simpletest (a PHP unit testing framework).
I couldn't get it to work with TCL/TK or Freepascal so I do understand the process and that it is a non-trivial process.

I wrote my first serious program with Hypercard in the late 80's, a cash register program for a service station, and am delighted to be reacquainted with it through LiveCode.

Having established some slight credentials let's get to the problem.

I am getting intermittent and unreliable logging. I have crawled the forums for post type comments but nothing seems to cover the issue I am having.
It seems to me that LC caches the http headers and returns them regardless of the URL I call.
Sometimes it even seems to cache the headers I send and resend them instead of the proper ones.

I have attached a sample stack which demonstrated the problem.
Changing the URL in the URL field works for the first few times but then it starts to get hung up and returns the same recieved headers almost regardless of the requested site.
I test with google, amazon, ebay, adobe, apple, microsoft, gmail etc. but you can also test with pretty much any site you like, the behaviour remains unreliable.

What have I missed? Is this really buggy behaviour ir is it me?

scrabbles
Posts: 25
Joined: Sat Dec 20, 2014 4:32 am

Re: How to clear the socket cache.

Post by scrabbles » Wed Sep 02, 2015 10:32 am

Hi ya,

If you are using the "load" command, there is a counterpart called "unload" that should clear the cache. Additionally, you can see what URLs have been cached by using "the cachedURLs" to verify.

Hope that helps.

- Mark

lilRalph
Posts: 25
Joined: Wed Aug 26, 2015 9:43 am

Re: How to clear the socket cache.

Post by lilRalph » Wed Sep 02, 2015 10:34 am

Thanks for the quick response.

I thought I had attached the stack but 'twasnt so.
It is now.

You will see in that that I am using load and unload but the behaviour remains buggy.

I will test the cachedUrls call though.

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: How to clear the socket cache.

Post by Thierry » Wed Sep 02, 2015 10:36 am

lilRalph wrote:Thanks for the quick response.

I thought I had attached the stack but 'twasnt so.
It is now.
Hi Ralph,

You can't attached a file right now; I think you need few more posts
to be able to do that...

Put ti in your dropbox or anywhere and provide a link to it.

Regards,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

lilRalph
Posts: 25
Joined: Wed Aug 26, 2015 9:43 am

Re: How to clear the socket cache.

Post by lilRalph » Wed Sep 02, 2015 10:40 am

G'Day Thierry, my first post appears to me to have a downloadable link to the file at the top of the post.
If that isn't the same for you then I'll make alternative arrangements.

I just tried the cachedUrls function and it shows empty while I am requesting amazon and getting ebay headers.

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: How to clear the socket cache.

Post by Thierry » Wed Sep 02, 2015 11:02 am

lilRalph wrote:G'Day Thierry, my first post appears to me to have a downloadable link to the file at the top of the post.
Oops, sorry for the noise. There it is :)

Regards,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: How to clear the socket cache.

Post by Thierry » Wed Sep 02, 2015 11:54 am

Hi,

Managed to make it works with few changes..

Code: Select all

function fnGetStaticHeaders pHost, pCookies,pReferer
   put empty into tHeaders
   -- if pHost is not empty then  put "Host:" && pHost & cr into tHeaders
   
   put cr & "User-Agent: " &quote&"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:40.0) Gecko/20100101 Firefox/40.0"&quote after tHeaders
   put cr & "Accept: " &quote&"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"&quote after tHeaders
   put cr & "Accept-Language: " &quote&"en-gb,en;q=0.5"&quote after tHeaders
   put cr & "Accept-Encoding: " &quote&"gzip,deflate"&quote after tHeaders
   put cr & "Connection: " &quote&"keep-alive"&quote after tHeaders
   --   if pReferer is not empty then
   --      put cr & "Referer:" && pReferer after tHeaders
   --   end if
   --   if pCookies is not empty then
   --      put cr & "Cookie: lang=english;" & pCookies after tHeaders
   --   end if
   return tHeaders
end fnGetStaticHeaders
BTW, I'm working on a current project which just does what you want,
and I'm quite happy so far with all the tests...

HTH,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: How to clear the socket cache.

Post by Thierry » Wed Sep 02, 2015 11:56 am

and I changed this settings to have some feedback:

Code: Select all

   libURLFollowHttpRedirects  false -- true

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

lilRalph
Posts: 25
Joined: Wed Aug 26, 2015 9:43 am

Re: How to clear the socket cache.

Post by lilRalph » Wed Sep 02, 2015 12:23 pm

Thierry that does work and it seems to be reliable. Excellent work.
It is very interesting that putting the quotes around the text makes a difference, I am supposing that LC treats it as a string then as opposed to objects (?).

However, I will need to have the cookies at the very least because, as you would know, Wordpress relies on the cookies for access.

I am happy to not have to use socket manipulation directly.

OK, not a bug.

Thanks.

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: How to clear the socket cache.

Post by Thierry » Wed Sep 02, 2015 12:30 pm

lilRalph wrote:Thierry that does work and it seems to be reliable. Excellent work.
Glad that you're happy with it :)
It is very interesting that putting the quotes around the text makes a difference, I am supposing that LC treats it as a string then as opposed to objects (?).
Well, reading closely at headers, those quotes are mandatories.
And yes, it's just plain text.
However, I will need to have the cookies at the very least because, as you would know, Wordpress relies on the cookies for access.
Check in these forums for an excellent post from sparkout, who explains very nicely and
precisely how to deal with cookies.

Regards,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

lilRalph
Posts: 25
Joined: Wed Aug 26, 2015 9:43 am

Re: How to clear the socket cache.

Post by lilRalph » Wed Sep 02, 2015 12:58 pm

Thanks again Thierry, I removed this bit
-- if pHost is not empty then put "Host:" && pHost & cr into tHeaders
as I found that LC puts in the Host: part correctly.

Removing that part enables the cookies to operate.
I will check out sparkout's cookie handling.

For those who read this later, the link to sparkout's cookie handling is here http://forums.livecode.com/viewtopic.ph ... ers#p86063 .

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: How to clear the socket cache.

Post by Thierry » Wed Sep 02, 2015 1:22 pm

lilRalph wrote:Thanks again Thierry, I removed this bit
-- if pHost is not empty then put "Host:" && pHost & cr into tHeaders
as I found that LC puts in the Host: part correctly.
Removing that part enables the cookies to operate.
As I did the first corrections quite fast, it seeems we do *not* need ot add these extra quotes!
So the problem was certainly the double Host definition...
I will check out sparkout's cookie handling.

For those who read this later, the link to sparkout's cookie handling is here http://forums.livecode.com/viewtopic.ph ... ers#p86063 .
Yep, that's the one :)

So you're in good hands with sparkout expertise :)

Good lck,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: How to clear the socket cache.

Post by SparkOut » Wed Sep 02, 2015 7:20 pm

Just for info, the pHost argument there was optional, I included it in the function because it was necessary for the specific site in question on that thread. It would have been better if I had mentioned it, and perhaps more succinctly, would have been better to have made the pHost argument the last one passed to the function, in which case it would be more elegant to leave it out optionally. (On the other hand, all the arguments are optional).

lilRalph
Posts: 25
Joined: Wed Aug 26, 2015 9:43 am

Re: How to clear the socket cache.

Post by lilRalph » Fri Sep 04, 2015 12:58 pm

Great forum response here. Fast, accurate and not agressive or belittling like some forums.
Keep up the great customer service here and LiveCode is destined for greatness.

Thanks Thierry for your help and feedback. I have also tested the quotes and decided to leave them in even though they seem to be essential.

Thanks also to sparkout for your input. I had read that the headers are replaced rather than required but updating the host shouldn't upset the routine.

I have plans for this programming tool, I hope I'm up to it.

Post Reply