views:

267

answers:

3

I'm trying to get two different apps to communicate through a file. I would like app 1 to append some text to a file, and app 2 to notice, and read the new bytes (not the whole file).

There is an event, ProgressEvent.PROGRESS, that is supposed to fire when new data is available on a FileStream, but it only fires when I first open the file.

Basically, I would like to leave the FileStream open, listening like a socket on the end of that file for changes. Is it possible? Any performance considerations?

Thanks1

A: 

I'd say keep a record of the filesize, check it periodically with a Timer, and then seek to the end of the old file when it gets bigger. With AIR 2.0 it should be easy, if you embed something akin to "tail -f".

Sophistifunk
Exactly, I thought that it would be built-in. It's not like watching a file for changes is rocket science. I found FileStream's progress event, but it doesn't seem to work. Thanks for your answer.
Sean Clark Hess
A: 

You can use the FileMonitor class that is part of Adobe's 'as3corelib' package to monitor files.

http://code.google.com/p/as3corelib/

It comes with FileMonitorEvent.CHANGE, MOVE and CREATE events.

Presentation and example here :

http://www.mikechambers.com/blog/2009/03/11/monitoring-file-changes-in-adobe-air/

Peiniau
Yeah, I was hoping to avoid using a timer. That's disappointing. I'll mark this answer as correct unless someone comes up with something better.
Sean Clark Hess
A: 

I understand that you probably want the socket-like 'interface' for reading/writing files between two apps, but you may be able to accomplish the same thing with a local SharedObject and a 'manager' class that uses the localConnection class to do certain things to that sharedObject/file. Random thought....

jeremym
Good idea, but it would be the same as a flat file unless an opened local shared object fires an event when someone else writes to it.
Sean Clark Hess
True. I was under the impression that this was more of a 1:1 "app relationship." I too would try to avoid the timer, simply for memory annoyances... so IF you have a "many:many apps relationship," you could play the messaging server game and subscribe to a messaging feed.However, if you do have a 1:1 app relationship, the ONLY purpose of the localConnection would be to have the manager class you create do the 'event firing' that you spoke of. But, like I said, only a good option if the scenerio of app1 and app2 exist only as you originally described.Good luck either way.
jeremym