AS3与Red5之间的参数传递

差不大一年没去动red5了,现在因为项目需要又开始使用red5,呵呵,先写些基本应用吧
参数传递是最基本的,之前是as2,现在用as3与red5 0.63了,几乎没什么变化.不过flash这边的可以传递的参数也就多了一些.就基本的是
String,int,Number,Boolean,Array,对应到red5这边是String,int,double,boolean,List
下面看基本的代码吧:
Flash:

/**
 * @(#)ParamRed5.as
 * @author soda.C
 * @version  1.0
 * <br>Copyright (C), 2007 soda.C
 * <br>This program is protected by copyright laws.
 * <br>Program Name:GameHall
 * @data 2008-2-19
 */
package org.sujun.red5.test 
{
    import flash.display.Sprite;
    import flash.net.NetConnection;
    import flash.events.NetStatusEvent;
    import flash.events.SecurityErrorEvent;
    import flash.net.Responder;
    /**
     * 测试flash与red5之间参数的传递
     */
    public class ParamRed5 extends Sprite 
    {
        private var netConnection:NetConnection;
        
        public function ParamRed5():void
        {
            netConnection    = new NetConnection();
            
            netConnection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
            netConnection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
            
           netConnection.connect("rtmp://localhost/paramtest");

        }
        
         private function netStatusHandler(event:NetStatusEvent):void 
         {
             trace("连接状态:" + event.info["code"]);
             
            switch (event.info["code"]) 
            {
                case "NetConnection.Connect.Success":
                    trace("连接成功.....");
                    //呼叫服务器的baseParam方法,传递基本参数,string,int,number,Boolean
                    netConnection.call("baseParam", new Responder(baseParamResult),"soda.C",24,1000.1,false);
                    //封装数组,int
                    var ary:Array = new Array();
                    ary.push(1);
                    ary.push(2);
                    ary.push(3);
                    //封装数组,String
                    var ary1:Array = new Array();
                    ary1.push("a");
                    ary1.push("b");
                    ary1.push("c");
                    netConnection.call("receiveArray", new Responder(baseParamResult),ary,ary1);
                    break;
                case "NetStream.Play.StreamNotFound":
                    trace("Stream not found: ");
                    break;
            }
        }
        
        private function baseParamResult(obj:Object):void
        {
            trace(obj);
            trace("响应了.....");
        }
        private function securityErrorHandler(event:SecurityErrorEvent):void 
        {
            trace("securityErrorHandler: " + event);
        }
    }
}

 
接下来看java代码
ParamRed5App.java,该类继承了ApplicationAdapt

package org.sujun.red5.test;

import java.util.List;

import org.red5.server.adapter.ApplicationAdapter;

/**
 * 存放被flash客户端调用的方法
 */
public class ParamRed5App extends ApplicationAdapter
{
    public ParamRed5App()
    {
        System.out.println("被初始化了......");
    }
    /**
     * 接受服务器传过来的基本参数
     */
    public void baseParam(String name, int age, double value, boolean flag)
    {
        System.out.println("----name----" + name);
        System.out.println("----age----" + age);
        System.out.println("----value----" + value);
        System.out.println("----flag----" + flag);
    }
    /**
     * 接受客户端传递过来的数组
     */
    public void receiveArray(List<Integer> intArray, List<String> strArray)
    {
        for(int i = 0; i < intArray.size(); i++)
        {
            System.out.println("----intArray----" + intArray.get(i).intValue());
        }
        for(int i = 0; i < intArray.size(); i++)
        {
            System.out.println("----strArray----" + strArray.get(i));
        }
    }
}

 
代码很简单.......直接复制过去,建立一个red5应用就可以使用了

你可能感兴趣的:(C++,c,应用服务器,C#,Flash)