zoukankan      html  css  js  c++  java
  • 即时通信(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 onError(event:Event):void
    			{
    				this.lblResult.text = "调用方法失败!";
    			}
    		]]>
    	</mx:Script>
    	
    </mx:Application>
  • 相关阅读:
    遗传算法求解旅行商(TSP)问题 -- python
    office 小技巧
    oracle创建dblink
    c# equals与==的区别
    两人之间的一些参数
    .net 枚举(Enum)使用总结
    SQL Server 日期的加减函数: DATEDIFF DATEADD
    jquery操作select
    AS3帮助手册
    Razor和HtmlHelper的使用意义
  • 原文地址:https://www.cnblogs.com/fx2008/p/4222244.html
Copyright © 2011-2022 走看看