C++ rtmp ZeroC ICE

海阔天空 张翼飞翔

我的学习日记
随笔 - 75, 文章 - 2, 评论 - 126, 引用 - 0
数据加载中……

Red5服务端和Flash方法相互调用

服务端代码
package org.zyf.myServer;//需要修改
import org.red5.server.adapter.ApplicationAdapter;
import org.red5.server.api.IConnection;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.red5.server.api.Red5;
import org.red5.server.api.service.IServiceCapableConnection;

public class Application extends ApplicationAdapter {
    
    
protected static Log log = LogFactory.getLog(Application.class.getName());
    
public String CallServer(String str){    
        System.out.println(
"user connected.param= " + str ); 
         IConnection myConn
=Red5.getConnectionLocal();
        
if (myConn instanceof IServiceCapableConnection)
        
{
            
//转发消息
            IServiceCapableConnection sc = (IServiceCapableConnection) myConn;
            sc.invoke(
"CallBack"new Object[]{"wellcome"});          
        }

        
return "hellow";
    }


    
public boolean appConnect(IConnection conn, Object[] params) {
        
// Trigger calling of "onBWDone", required for some FLV players
        
        
if (params == null || params.length == 0{
            log.debug(
"user unknown connected");
            
// NOTE: "rejectClient" terminates the execution of the current method!
            
//rejectClient("No username passed.");
        }

        
else
        
{
            log.debug(
"user "+params[0]+" connected");
        }

 
        
return super.appConnect(conn, params);
    }


}



Flash代码:
//import flash.net.Responder; 

NetConnection.defaultObjectEncoding 
= flash.net.ObjectEncoding.AMF0;
var nc:NetConnection 
= new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS,StatusHander);
nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR,ErroHander);
nc.connect(
"rtmp://192.168.10.10/myServer");
trace(
"connect..");


var obj:Object 
= new Object();
function StatusHander(event:NetStatusEvent):
void
{
    var info:Object 
= event.info;
    
    trace(
"StatusHander");
    
switch(info.code)
    
{
        
case "NetConnection.Connect.Success":
            trace(
"Sucess");
            nc.client 
= this;            
            nc.call(
"CallServer",new Responder(Result),"msg=NC.call");
            
break;
        
case "NetConnection.Connect.Failed":
            trace(
"Failed");
            
break;
        
default:
            trace(info.code);
            
break;
    }

}

var a:
int=0;
function Result(obj:Object):
void 
        

                trace(
"i got it: "+obj); 
        }
 
function ErroHander(event:AsyncErrorEvent):
void
{
    trace(
"Erro:");
}


function CallBack(str:String):String
{
    trace(
"CallBack()"+str);
    
return str+" len = "+ str.length;
}


//stop();

输出:
connect..
StatusHander
Sucess
CallBack()wellcome.
i got it: hellow

posted on 2008-04-02 13:51 ZhangEF 阅读(1953) 评论(1)  编辑  收藏 所属分类: rtmp

评论

# re: Red5服务端和Flash方法相互调用  回复  更多评论   

这篇文章算是一般吧,只是写上了java服务端代码,和flash 的代码,但是服务器的配置一点都没有提到,都没有太大的参考价值
2011-03-30 11:06 |