首页 > 代码库 > 即时通信(RPC)的Rtmp实现--配置篇

即时通信(RPC)的Rtmp实现--配置篇

http://flexman.blog.sohu.com/129838570.html

http://flexman.blog.sohu.com/130007574.html

 

step 1: 首先要确定RTMP的端口,可以利用netstat -an来查看

step 2: 修改services-config.xml,确保有rtmp的相关节点:

<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()

step 5: 在应用程序目录(MyChatRoom)里添加配置文件app.config,内容如下:

<?xml version="1.0" encoding="utf-8"?><configuration>	<application-handler type="ServiceLibrary8.MyChatApp"/></configuration>

step 6: 新建Flex项目,分为 连接rtmp 和 调用方法 两部分来实现

服务器端:

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 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 one rror(event:Event):void			{				this.lblResult.text = "调用方法失败!";			}		]]>	</mx:Script>	</mx:Application>

即时通信(RPC)的Rtmp实现--配置篇