[AS3]Red5流媒体RTMP服务端和Flash方法相互调用的示例代码
[AS3]Red5流媒体RTMP服务端和Flash方法相互调用的示例代码,Red5服务端,rtmp播放器
服务端代码
- 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
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...