We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › question re : file reading w/ loadstrings()
Page Index Toggle Pages: 1
question re : file reading w/ loadstrings() (Read 2361 times)
question re : file reading w/ loadstrings()
Oct 26th, 2007, 11:40pm
 
Hi there.

I'm working on a research project, and have been asked to get Second Life and processing to communicate.

I have successfully gotten processing to write a file with a php script, and then access it from SL (with slhttprequest), but I am having trouble doing the reverse.

This part of this very simple experiment works as such :
There are three coloured toruses in Second Life, that when I click any of them, accesses a php script which writes either a 1,2 or a 3 to a text file, depending on which torus clicked. (it writes this file to the /data/ directory of my sketch) The file is called sl2proc.txt

Then, I have this simultaneous Processing sketch running, where I attempt to access the file with the loadStrings function.

The thing is : It works the first time, ie. When I load my browser (firefox) up, and load the sketch url, it accesses the file and pulls the proper data.

Then, when I change the data in the textfile (either through clicking a torus, or manually editting the text file), suddenly Processing wont recognize the change (It tries to update every 3 seconds).

It continues to tell me that the data it has pulled from the file is the same (by not changing the colour indicator, and via a println). If I close firefox at that point, and reopen it, the sketch now recognizes the change and updates accordingly. Just closing the sketch window and/or reloading the Processing url doesn't fix it. I need to completely close firefox to have it access the file anew.

It seems like, when I first use Loadstrings, the Java runtime environment puts the textfile in memory, and refuses to shake it, despite the actual change in the file. Is there some way to address this? To get processing to recognize that the file has been modified? to forcibly close the filestream?

http://caferisko.ca/TEST/test3/sl2proc/applet/index.html
// this is the applet

http://slurl.com/secondlife/Tkachiev/91/211/601
// this is where the modifying torus are
// they are on a platform 601 ft in the air.

Any help would be greatly appreciated
thanks!
max
Re: question re : file reading w/ loadstrings()
Reply #1 - Oct 27th, 2007, 8:43am
 
Smiley

when you call:
loadStrings("sl2proc.txt");

processing is gonna look for the file first in the data-folder which get's exported into (!) the jar of your applet. you probably have a copy in there, so it load the first time but never updates.

try loadStrings with the full path (url in your case) to the text file and remove the one from the data folder.

F
Re: question re : file reading w/ loadstrings()
Reply #2 - Oct 28th, 2007, 1:44am
 
That had originally been my problem,

When that was the case, the loadstrings() always read the same data, until I re-exported the processing file. Which had me very confused. Exactly like you say.

I did figure that out, and now I remove all of the text files before I recompile.

but - since the sketch reads the proper info when I reboot the browser (firefox), this suggest that it actually is pointed at the proper file (and not accessing some constant file within its jar), does it not?

thanks for
the response though.
I may try using loadstrings with a full path, instead of just a relative one, to see if that helps.




Re: question re : file reading w/ loadstrings()
Reply #3 - Oct 28th, 2007, 9:08am
 
yes. sorry about the smiley, put that in because i ran into that problem myself once and i can remember how confusing it was ..

try:
data/sl2proc.txt
or
http://caferisko.ca/TEST/test3/sl2proc/applet/data/sl2proc.txt

F
Re: question re : file reading w/ loadstrings()
Reply #4 - Nov 5th, 2007, 11:06pm
 
Well, I tried the absolute path string, with no success.

.. but, I've found that if I open the Java Console Control Panel, and go into the 'cache' section, and browse the 'current files' in the cache, I can see the SL2proc.txt there.

If I delete that entry from the cache,
the sketch will work properly, and load proper data from the file, but of course then it puts this new datafile back in the cache, and refuses to budge from it unless I delete the file from the cache again.

So apparently there is no problem with pathnames, or filenames, or the loadstrings function at all, but rather a problem with the Java console saving a cached version of the file I access, and then refusing to re-access it on request - relying instead on reading the saved version in memory.

That is why when I shut Firefox (or IE) right down, and reload it, it disengages from the cache, and reaccesses the file on the server anew.

Is there some function I can use to reset my Java cache from within processing?

thanks
max

Re: question re : file reading w/ loadstrings()
Reply #5 - Nov 5th, 2007, 11:37pm
 
I'd hate to suggest this but you could run command-line commands from within Processing (in this case, a Java library would help) and force delete that cache file that's been giving you problems.

Not only are there serious security implications to this method, it will be different from machine to machine but depending on your needs it might be a decent solution.
Re: question re : file reading w/ loadstrings()
Reply #6 - Nov 5th, 2007, 11:49pm
 
if the data is being pulled from a server, try adding a ? and a random number to the end of the url, to fool the cache. or disable the java/browser cache. but we're basically at the mercy of how the browser chaches things here.
loadStrings("http://somesite.com/yourthing.php?1432425");

to run locally, use a full path name to the file:
loadStrings("/home/yourname/Desktop/somefile.txt");
which should not cache.
Re: question re : file reading w/ loadstrings()
Reply #7 - Nov 6th, 2007, 12:17am
 
Fry!

You genius!

Thanks thanks thanks.
I have been yanking my hair out,
and now, I can let it grow casually back.
It works.

That random number worked like a charm.

Thanks to everyone else too.

Great response time.

ttyl
Max
Re: question re : file reading w/ loadstrings()
Reply #8 - Aug 27th, 2009, 11:57am
 
hey maxtuckett!

I am also doing reasearching work about Second Life and Real Word for my Master degree, i would like to share some ideias with you, and discuss some topics as well. Fell free to e-mail me fm_84@clix.pt or send a IM to Filipe Roff, inworld.

Thanks Wink
Re: question re : file reading w/ loadstrings()
Reply #9 - Aug 27th, 2009, 1:20pm
 
this post is 2 years old so maybe its a better idea to write him and not wait for him to read this post, cause he probably wont
Page Index Toggle Pages: 1