http://flexman.blog.sohu.com/129838570.htmlhtml
http://flexman.blog.sohu.com/130007574.html服務器
step 1: 首先要肯定RTMP的端口,能夠利用netstat -an來查看app
step 2: 修改services-config.xml,確保有rtmp的相關節點:flex
<channel-definition id="my-rtmp" class="mx.messaging.channels.RTMPChannel"> <endpoint uri="rtmp://{server.name}:8323" class="flex.messaging.endpoints.RTMPEndpoint"/> <properties> <idle-timeout-minutes>20</idle-timeout-minutes> </properties> </channel-definition>
step 3: 在網站新建apps目錄,並添加MyChatRoom文件夾做爲應用程序目錄網站
step 4: 定義MyChatApp類繼承自FluorineFx.Messaging.Adapter.ApplicationAdapter,並定義供客戶端調用的方法GetResult()this
step 5: 在應用程序目錄(MyChatRoom)裏添加配置文件app.config,內容以下:spa
<?xml version="1.0" encoding="utf-8"?> <configuration> <application-handler type="ServiceLibrary8.MyChatApp"/> </configuration>
step 6: 新建Flex項目,分爲 鏈接rtmp 和 調用方法 兩部分來實現code
服務器端:server
using System; using System.Collections.Generic; using System.Text; using FluorineFx.Messaging.Adapter; namespace ServiceLibrary8 { public class MyChatApp : ApplicationAdapter { public string GetResult(string name, int age) { return name + " is " + age + " years old"; } } }
Flex端:xml
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> <mx:Button x="211" y="69" label="鏈接RTMP" click="onConnectClick()" /> <mx:Button x="190" y="113" label="調用RTMP提供的方法" click="onFunctionClick()" /> <mx:Label id="lblResult" x="230" y="31" text="Label"/> <mx:Script> <![CDATA[ import mx.rpc.events.ResultEvent; private var nc:NetConnection; private function onConnectClick():void { nc = new NetConnection(); nc.connect("rtmp://localhost:8323/MyChatRoom"); nc.addEventListener(NetStatusEvent.NET_STATUS, netStatus); nc.client = this; } private function netStatus(event:NetStatusEvent):void { var strCode:String = event.info.code; if(strCode=="NetConnection.Connect.Success") { this.lblResult.text = "鏈接RTMP成功!"; } else { this.lblResult.text = "鏈接RTMP失敗!"; } } private function onFunctionClick():void { var responder:Responder = new Responder(onResult,onError); nc.call("GetResult",responder,"袁承志",20); } private function onResult(result:String):void { this.lblResult.text = "方法返回結果:" + result; } private function onError(event:Event):void { this.lblResult.text = "調用方法失敗!"; } ]]> </mx:Script> </mx:Application>