[RED5]实现Flex与Red5的通讯源代码示例
服务器端Application提供一个供Flex客户端远程调用的方法getMyName,代码如下
服务器端Application提供一个供Flex客户端远程调用的方法getMyName,代码如下:
- package org.chy.flex02;
- import org.red5.server.adapter.ApplicationAdapter;
- public class Application extends ApplicationAdapter{
- public String getMyName(String id){
- if("001".equals(id)){
- return "ChenYang";
- }
- return "JAVA&Flex";
- }
- }
客户端Flex程序,当用户点击'get name'按钮时,远程调用getMyName方法。响应给客户端
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="355" height="176" applicationComplete="init()">
- <mx:Script>
- <!--[CDATA[
- import flash.net.NetConnection;
- import flash.net.NetStream;
- private var nc:NetConnection
- private function init():void{
- nc = new NetConnection();
- nc.addEventListener(NetStatusEvent.NET_STATUS,connectHandler);
- nc.client = this;
- nc.connect("rtmp://localhost:1935/Flex02");
- }
- private function getName():void{
- nc.call("getMyName",new Responder(okHandle,failureHandle),"001");
- }
- public function okHandle(result:String):void{
- trace("ok:"+result);
- myname.text=result;
- }
- public function failureHandle(result:String):void{
- trace("failure:"+result);
- }
- private function connectHandler(evt:NetStatusEvent):void{
- trace("code:"+evt.info.code);
- if(evt.info.code != "NetConnection.Connect.Success"){
- nc.removeEventListener(NetStatusEvent.NET_STATUS,connectHandler);
- }
- }
- public function onBWDone():void{
- }
- ]]-->
- </mx:Script>
- <mx:Button x="36" y="72" label="get name" click="getName()"/>
- <mx:TextInput x="124" y="72" width="173" id="myname"/>
- </mx:Application>
.
热门文章推荐
- [Red5]Red5之Flash流媒体服务器的安装与使用教程完整版(组图)
- [RED5]搭建RED5直播用流媒体服务(搭直播环境)
- [RED5]Red5的直播与点播的压力测试(并发数的测试)
- [RED5]red5流媒体服务器(开源免费)的安装方法
- [RED5]用red5做视频直播(red5流媒体直播)
- [RED5]Red5在线录制音视频源代码示例
- [RED5]Red5 Client 连接 Red5Server java代码
- [RED5]red5流媒体播放平台搭建环境方法
请稍候...