[Red5] Returning multiple values to Flash from Red5 app
Bill Goulding
billgoulding at gmail.com
Fri Aug 22 10:00:58 PDT 2008
Should this solution work for client code written in AS2 as well as AS3?
I am able to get this working in an AS3 client, but my project is coded in
AS2...
My AS2 client code is as follows:
var nc:NetConnection = new NetConnection();
nc.client = this;
// connect to the local Red5 server
nc.connect("rtmp://localhost:1935/myTest");
nc.onStatus = function(info){
trace(info.code);
if(info.code == "NetConnection.Connect.Success"){
nc.call("upload", new scriptMessage());
}
}
function scriptTrace(obj) {
trace("ping");
trace(obj.toString());
}
function scriptMessage() {
this.onResult = function(result) {
trace(result)
}
}
And my Java server code is as follows:
package org.red5.server.webapp.mytest;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.red5.server.api.Red5;
import org.red5.server.api.service.IServiceCapableConnection;
import org.red5.server.adapter.ApplicationAdapter;
public class Application extends ApplicationAdapter
{
public String upload() throws IOException
{
// A Runtime object has methods for dealing with the OS
Runtime r = Runtime.getRuntime( );
Process p; // Process tracks one external native process
BufferedReader is; // reader for output of process
Object line;
IServiceCapableConnection sc = (IServiceCapableConnection)
Red5.getConnectionLocal();
p = r.exec("/Users/Bill/Desktop/upload.command");
System.out.println("In Main after exec");
// getInputStream gives an Input stream connected to
// the process p's standard output. Just use it to make
// a BufferedReader to readLine( ) what the program writes out.
is = new BufferedReader(new InputStreamReader(p.getInputStream( )));
while ((line = is.readLine()) != null)
{
System.out.println(line);
sc.invoke("scriptTrace", new Object[]{line});
}
System.out.println("In Main after EOF");
try {
p.waitFor( ); // wait for process to complete
} catch (InterruptedException e) {
return "error";
}
System.err.println("Process done, exit status was " + p.exitValue( ));
return ("Process done, exit status was " + p.exitValue( ));
}
}
AS3 client code that works is:
flash.events.NetStatusEvent;
// create our responder to pass to Red5 so it knows where
// to return the data
var responder:Responder = new Responder(scriptTrace, null);
// create basic netConnection object
var nc:NetConnection = new NetConnection();
// point the NetConnection's scope to this object
nc.client = this;
function onBWDone(...rest):void
{
// has to be present
}
// connect to the local Red5 server
nc.connect("rtmp://localhost:1935/myTest");
// add status event listener. When it's a success, you make the call
nc.addEventListener(NetStatusEvent.NET_STATUS, handleNetStatus);
function handleNetStatus(e:NetStatusEvent):void
{
trace(e.info.code);
switch(e.info.code)
{
case "NetConnection.Connect.Success":
//nc.call("addSomething", responder, 2, 3);
nc.call("upload", responder);
break;
}
}
function scriptTrace(obj:Object):void
{
if (obj != "script_completed"){
trace(obj.toString());
}
}
Thanks,
Bill
On Thu, Aug 21, 2008 at 5:09 PM, Bill Goulding <billgoulding at gmail.com>wrote:
> Thank-you so much for the example code Prabhu,
> I think that you just saved me a ton of time...
>
>
> On Thu, Aug 21, 2008 at 4:43 PM, Prabhu Tamilarasan (omNovia) <
> ptamilarasan at omnovia.com> wrote:
>
>> If you want periodic updates as your shell script runs, instead of
>> returning a value, call a function on the client passing one line of output
>> at a time.
>>
>>
>>
>> IServiceCapableConnection sc = (IServiceCapableConnection)
>> Red5.getConnectionLocal();
>>
>>
>>
>> while ((line = is.readLine( )) != null)
>>
>> {
>>
>> System.out.println(line);
>>
>> sc.invoke("shellOutput", new Object[]{line});
>>
>> }
>>
>>
>> ------------------------------
>>
>>
>>
>> [image: http://www.omnovia.com/images/mailicon.gif]
>> next generation web conferencing
>>
>> Prabhu Tamilarasan
>> Senior Software Engineer
>>
>> 675 Bering Drive, Suite 290
>> Houston, TX 77057 USA
>> www.omnovia.com
>>
>> ptamilarasan at omnovia.com
>>
>> T +1.281.500.4065 x 731
>> ------------------------------
>>
>>
>>
>> *From:* red5-bounces at osflash.org [mailto:red5-bounces at osflash.org] *On
>> Behalf Of *Bill Goulding
>> *Sent:* Thursday, August 21, 2008 2:50 PM
>> *To:* red5 at osflash.org
>> *Subject:* Re: [Red5] Returning multiple values to Flash from Red5 app
>>
>>
>>
>> Thanks,
>>
>>
>>
>> I might end up doing this - I was hoping that I could trigger a bash
>> script once, and then provide responses back to flash as they occured...
>>
>> On Thu, Aug 21, 2008 at 3:31 PM, Andy Shaules <bowljoman at hotmail.com>
>> wrote:
>>
>> Hello,
>>
>>
>>
>> Try using an array, and push, or ArrayCollection and return it loaded with
>> the values.
>>
>> ----- Original Message -----
>>
>> *From:* Bill Goulding <billgoulding at gmail.com>
>>
>> *To:* red5 at osflash.org
>>
>> *Sent:* Thursday, August 21, 2008 12:27 PM
>>
>> *Subject:* [Red5] Returning multiple values to Flash from Red5 app
>>
>>
>>
>> Hi All,
>>
>>
>>
>> I am a Java novice that is trying to connect a Flash SWF with the Bash
>> Shell via a local Red5 server on a Linux system (though OSX is my
>> development platform)
>>
>>
>>
>> Thus far, have successfully been able to get Flash to trigger shell
>> scripts on my local system (using a Red5 app given below)
>>
>>
>>
>> I also have been able to capture the output of these shell scripts via
>> Java's Process -> getInputStream in my Red5 app and pass them back to Flash
>> - sort of...
>>
>>
>>
>> I would like for my Red5 app to return multiple values to Flash as they
>> are processed, and presently I am am only able to return the first value
>> that my script produces.
>>
>>
>>
>> I know that this is because I am using a 'Return' statement in the Red5
>> app to send the values back to Flash - 'Return' is terminating the Red5 app
>> after the first value sent.
>>
>>
>>
>> I have been going through the Red5 API trying to suss out the method for
>> sending multiple messages from a Red5 app to a client, and haven't been
>> having any luck.
>>
>>
>>
>> My Java code is as follows:
>>
>>
>>
>> package org.red5.server.webapp.mytest;
>>
>>
>>
>> import java.io.BufferedReader;
>>
>> import java.io.IOException;
>>
>> import java.io.InputStreamReader;
>>
>>
>>
>> import org.red5.server.adapter.ApplicationAdapter;
>>
>>
>>
>>
>>
>> public class Application extends ApplicationAdapter
>>
>> {
>>
>> public String launchSomething() throws IOException
>>
>> {
>>
>> // A Runtime object has methods for dealing with the OS
>>
>> Runtime r = Runtime.getRuntime( );
>>
>> Process p; // Process tracks one external native process
>>
>> BufferedReader is; // reader for output of process
>>
>> String line;
>>
>>
>>
>> p = r.exec("/Users/Bill/Desktop/timezone.command");
>>
>>
>>
>> System.out.println("In Main after exec");
>>
>>
>>
>> // getInputStream gives an Input stream connected to
>>
>> // the process p's standard output. Just use it to make
>>
>> // a BufferedReader to readLine( ) what the program writes out.
>>
>> is = new BufferedReader(new InputStreamReader(p.getInputStream( )));
>>
>>
>>
>> while ((line = is.readLine( )) != null)
>>
>> {
>>
>> System.out.println(line);
>>
>> return line;//How else do I return these values to Flash?
>>
>> }
>>
>>
>>
>> System.out.println("In Main after EOF");
>>
>> try {
>>
>> p.waitFor( ); // wait for process to complete
>>
>> } catch (InterruptedException e) {
>>
>> return null;
>>
>> }
>>
>> System.err.println("Process done, exit status was " + p.exitValue( ));
>>
>> return null;
>>
>> }
>>
>> }
>>
>>
>>
>> Thanks,
>>
>>
>>
>> Bill
>>
>>
>> ------------------------------
>>
>> _______________________________________________
>> Red5 mailing list
>> Red5 at osflash.org
>> http://osflash.org/mailman/listinfo/red5_osflash.org
>>
>>
>> _______________________________________________
>> Red5 mailing list
>> Red5 at osflash.org
>> http://osflash.org/mailman/listinfo/red5_osflash.org
>>
>>
>>
>> _______________________________________________
>> Red5 mailing list
>> Red5 at osflash.org
>> http://osflash.org/mailman/listinfo/red5_osflash.org
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://osflash.org/pipermail/red5_osflash.org/attachments/20080822/172fdd23/attachment-0001.html
More information about the Red5
mailing list