Topic: Named Pipes......Understanding use from Flash

Based on following sample code:

// Launch a program which is likely to remain resident, and will not be
// terminated on close. Should not be used for anything that will block!
_pipeDaemon = ASnative(5,190);
res = _pipeDaemon( "/mnt/usb/bin/readbot >/mnt/usb/readbot.log 2>/mnt/usb/readbot.err &" );
trace( "daemon launch result = " + res );
// Open a pipe for reading
_pipeOpen = ASnative(5,191);
g_handle = _pipeOpen( "tail -f /mnt/usb/readbot.err", "r" );
trace( "pipe open result = " + g_handle );

// Set input event notification handler for a pipe which was opened for reading.
// Call again with an empty string to switch back to normal reading.
// When this is active attempts to read will always return an empty string.
this.myListener = Object();
this.myListener.onEvent = function( status, comments )
{
   if (status == "data")
   {
       trace( "got myListener.DataReceived.onEvent(" + comments + ")" );
   }
   else
   {
       // only data and eof supported
       trace( "status = " + status );
   }
};
ExtendedEvents.DataReceived.addListener( myListener );

trace( "Switching to event notification for handle " + g_handle );
_pipeSetInput = ASnative(5,192);
_pipeSetInput( g_handle, "DataReceived" );

// Read from a pipe previously opened for reading. If nothing available returns empty string.
_pipeRead = ASnative(5,193);
s = _pipeRead( g_handle );
if (s != undefined && s != "")
{
   trace( "data=" + s );
}
// Write to a pipe previously opened for writing.
_pipeOpen = ASnative(5,191);
_pipeWrite = ASnative(5,194);
writeTest = _pipeOpen( "./wptest.sh >wptest.out", "w" );
trace( "Write handle result = " + writeTest );
_pipeWrite( writeTest, "first_line of test\n" );

// Close a pipe previously opened for reading or writing
_pipeClose = ASnative(5,195);
_pipeClose( writeTest );

I am still trying to understand the parameters passed to the pipe opening call.  It seems you do not name the pipe file, but seem to need to execute a process to get the handle (I think).
Looking at the ,write to a pipe, sample code, it seems I need a shell script that redirects its output to the named pipe.
Do I really need to provide a shell script along with the Flash program just to write to a named pipe?

Also

I noticed a process (using ps) that shows the following binary /usr/bin/chumbpipe.   It seems to be able to take a sending and receiving named pipes as parameters.  Can I use this in my Flash program to read and write to a pipe? and how do I use it?

Thanks

Mark

Re: Named Pipes......Understanding use from Flash

Henry is the expert on this stuff, perhaps he'll chime in.

The pipe subsystem uses chumbpipe for the implementation.

Not also that this mechanism does not work from widgets, only Flash movies run directly on the device.

Re: Named Pipes......Understanding use from Flash

Hi Mark,

The example you quote above looks like something I wrote to illustrate all the various ways in which you might use the ASnative interface to chumbpipe.

chumbipe is a helper app which is launched by flashplayer on startup. You can't run a second instance of it. Basically it gets around linux process limitations on a non-swapping VM system when the parent process has a large VM footprint (as flashplayer does).

If you're familiar with C programming under linux, the ASnative calls basically give you a way of doing system(), popen(), pclose() etc. from a flash movie loaded via -i. You don't need to create a shell script, and basically whatever you pass as the first argument to pipeopen (ASnative(5,191);) will be launched by the shell. So you could do things like redirect stderr or merge stderr into stdout.

I have a working example which reads from a GPS device. It works with a custom binary application written in C++ which handles intializing the serial port and cracking either NMEA or Garmin serial data. If you can tell me more about what you're trying to do I might be able to explain it better, or I can provide that as a working example.

In the above examples, you could also do something like this if you just wanted a way to append to a file:

// Open pipe for writing. Use cat to append to a log file
_pipeOpen = ASnative(5,191);
_pipeWrite = ASnative(5,194);
writeTest = _pipeOpen( "cat >>/mnt/usb/mylog.log", "w" );
trace( "Write handle result = " + writeTest );
_pipeWrite( writeTest, "first_line of test\n" );
_pipeWrite( writeTest, "Another line written to the log file\n" );
// We could also do this in onEnterFrame(), etc.
// Close a pipe previously opened for reading or writing
_pipeClose = ASnative(5,195);
_pipeClose( writeTest );

I hope that helps.

Re: Named Pipes......Understanding use from Flash

Hi Henry,
I have developed a UPnP Control point in 'C' that (using named pipes) allows for discovery of Media devices on a network and browsing of the media contained.

What I do is to have the UPnP control point open sending and receiving pipes upon startup and then wait on the input pipe for commands.
Then from Flash I want to write commands to the Control points input pipe and read back responses from the output pipe (the UPnP control point responds with XML) and then render the response to the Chumby screen.

For example:
To discover all UPnP media devices on the network I would write XML string <discover media="xxxxx"/> the the input pipe of the UPnP Control point, the Control Point then responds with XML on the output pipe, which contains the names of all the media devices found.

I am trying to understand how I would issue a command String from Flash to the named pipe file (perhaps /tmp/UPnP_input for example) and read responses back from another pipe (perhaps /tmp/UPnP_output for example).

Looking at Flash examples I am not sure I am to do it the same way as you would in 'C'.

Hope this clears up my issue.

Thanks for any help you can provide.

Mark

5 (edited by winneymj 2008-10-23 10:39:29)

Re: Named Pipes......Understanding use from Flash

Henry,
Now that I know it is using the popen and pclose I can understand how to access the pipes.

Essentially:

_pipeOpen = ASnative(5,191);

rHandle = _pipeOpen("tail -f /tmp/UPnP_input" ,"r"); // Open for Read
wHandle = _pipeOpen("cat >> /tmp/UPnP_output", "w"); // Open for write

 _pipeRead = ASnative(5,193);
s = _pipeRead( rHandle );
if (s != undefined && s != "")
{
   trace( "data=" + s );
}

_pipeWrite = ASnative(5,194);
_pipeWrite( wHandle, "first_line of test\n" );
_pipeClose = ASnative(5,195);
_pipeClose( rHandle );
_pipeClose( wHandle );