惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google Online Security Blog
Google Online Security Blog
G
Google Developers Blog
云风的 BLOG
云风的 BLOG
阮一峰的网络日志
阮一峰的网络日志
L
Lohrmann on Cybersecurity
Security Latest
Security Latest
博客园 - 【当耐特】
Microsoft Security Blog
Microsoft Security Blog
N
Netflix TechBlog - Medium
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
The GitHub Blog
The GitHub Blog
Vercel News
Vercel News
The Register - Security
The Register - Security
T
Tenable Blog
D
Docker
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
有赞技术团队
有赞技术团队
C
CXSECURITY Database RSS Feed - CXSecurity.com
Simon Willison's Weblog
Simon Willison's Weblog
S
Schneier on Security
Scott Helme
Scott Helme
C
Cyber Attacks, Cyber Crime and Cyber Security
C
CERT Recently Published Vulnerability Notes
罗磊的独立博客
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
H
Hackread – Cybersecurity News, Data Breaches, AI and More
K
Kaspersky official blog
Know Your Adversary
Know Your Adversary
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
The Blog of Author Tim Ferriss
aimingoo的专栏
aimingoo的专栏
Spread Privacy
Spread Privacy
P
Proofpoint News Feed
博客园 - 聂微东
NISL@THU
NISL@THU
T
Threat Research - Cisco Blogs
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
A
Arctic Wolf
V2EX - 技术
V2EX - 技术
H
Heimdal Security Blog
C
Check Point Blog
D
DataBreaches.Net
H
Help Net Security
www.infosecurity-magazine.com
www.infosecurity-magazine.com
L
LangChain Blog
宝玉的分享
宝玉的分享
V
Vulnerabilities – Threatpost
PCI Perspectives
PCI Perspectives
Recent Announcements
Recent Announcements
Martin Fowler
Martin Fowler

博客园 - OldHawk

android:themes.xml android:style.xml How to merge two images into one using Actionscript Flex(flash)检测摄像头的3种状态(是否被占用,没安装摄像头,正常) - OldHawk - 博客园 推荐几个Adobe Flex Builder 3的插件(代码格式化和fms服务器通讯文件(main.asc)编写) - OldHawk flex4中list与itemRenderer项目渲染器中子对象之间访问 install flashpolicyd Linux环境如何升级Python linux运行级别查看并更改研究 Flash builder 4 (Flex builder 4) 正式版序列号生成器 (转)基于svnserve的服务器,权限文件authz配置的常见问题及解答 Linux下SVN安装配置记录 (转)谈linux安全设置 Linux安全配置步骤简述 对linux安全设置中需要注意和掌握的地方 Linux操作系统下SSH默认22端口修改方法 图片与二进制及字符相互换化(转) MSDN帮助文档 "无法显示该网页" 的问题解决方案(转) - OldHawk 修改flex应用默认的装载界面
Fms3中client端与server端交互方式汇总
OldHawk · 2010-12-05 · via 博客园 - OldHawk

fms3中server端代码是写在asc文件中,客户端是broadcastMsg.swf
2者交互方式我总结如下:

1. 客户端呼叫服务器
服务器端main.asc代码如下:


Client.prototype.serverFun1 = function(value)
{
    return "value="+value
};

客户端代码如下:


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" 
    fontSize
="12" creationComplete="init()">
    
    
<mx:Script>
        
<![CDATA[    
        import mx.controls.Alert;
    
        private var netConnection:NetConnection;
        private var responder:Responder;
        private var appServer:String="rtmp://192.168.0.249/TestCode1";
            
        private function init():void
        {
            netConnection = new NetConnection();
            netConnection.connect(appServer);
            netConnection.client=this;
        }
        
        private function onClick(evt:MouseEvent):void
        {
            responder = new Responder(OkFun,ErrorFun);
            netConnection.call("serverFun1",responder,"va");
        }
            
        private function OkFun(re:String):void
        {
            Alert.show(re);
        }
        
        private function ErrorFun(info:Object):void
        {
            Alert.show( "error: " + info.description );
            Alert.show( "error: " + info.code );
        }
        
        
]]>
    
</mx:Script><mx:Button x="43" y="65" label="调用服务器" id="btn" click="onClick(event)"/>
    
</mx:Application>


代码说明:
Responder 类提供了一个对象,该对象在 NetConnection.call() 中使用以处理来自与特定操作成功或失败相关的服务器的返回值。
它有2个参数:第1个是成功调用回调的方法,第2个参数是调用失败时回调的方法

call () 方法  
public function call(command:String, responder:Responder, ... arguments):void
第1个参数:服务器端方法名
第2个参数:可选对象,用于处理服务器的返回值
第3个参数:传递给服务器端方法的值
 
本例题:点击按钮后,调用asc文件中的serverFun1方法,并传递参数“va”给它,serverFun1方法处理后方法一个值,要是成功就回调OkFun,并显示“value=va”字符串,要是调用失败(可能会遇到特定于当前操作的网络操作错误或与当前连接状态有关的错误)将回调ErrorFun,并显示错误信息

2. 服务器端呼叫指定的客户端
服务器端main.asc代码如下:

Code

客户端代码如下:

Code


代码说明:
Client.call() 在Flash客户机上异步的执行一个方法,并把值从Flash客户机返回到服务器。
用法 clientObject.call(methodName, [resultObj, [p1, ..., pN]])
第1个参数:客户端的方法名
第2个参数:当发送者期待一个来自客户机的返回值时需要这个参数。如果参数被传递但没有返回值被期待的话,则传递值null。结果对象可以是你定义的任何对象,并且,为了有用起见,这个结果对象应该有两个方法-onResult和onStatus,这些方法会在结果到达时被调用。如果远端方法的调用是成功的,则resultObj.onResult事件会被触发;否则,resultObj.onStatus事件将被触发。
第3个参数:传递给客户端的方法的值

本例题:启动后,连接成功,服务器接收请求,并调用改客户端的asyncServerCall方法(必须公有),asyncServerCall方法处理后返回值,要是处理成功onResult事件就被触发,要是处理失败onStatus事件就被触发。

3. 服务器端呼叫所有的客户端(广播)
服务器端main.asc代码如下:


application.onConnect = function(currentClient)
{
    application.acceptConnection(currentClient);
    application.broadcastMsg("showServerMsg",application.clients.length );
}

客户端代码如下:


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
 fontSize
="12" creationComplete="init()">
    
    
<mx:Script>
        
<![CDATA[
            
        import mx.controls.Alert;
        
        private var netConnection:NetConnection;
        private var appServer:String="rtmp://192.168.0.249/TestCode1";
        
        private function init():void
        {
            netConnection = new NetConnection();
            netConnection.connect(appServer);
            netConnection.client=this;
        }
        
        public function showServerMsg( n:Number ) :void
           {
               var msg:String ="已经有"+n.toString()+"位用户连接";
               Alert.show( msg );
           }
                
        
]]>
    
</mx:Script>
    
</mx:Application>


代码说明:
Application.broadcastMsg():把一条消息广播到所有连接的客户机,给每个客户机广播
这个方法相当于循环遍历Application.clients数组并在每一个独立的客户机上调用Client.call(),但这个方法的效率更高(尤其是当连接的客户机数量很大时)。唯一的不同是当你调用broadcastMsg()时你不能指定一个响应对象,除此以外,两种语法是一样的。
等同于如下:
//遍历客户端列表,分别call他们
for(var i=0;i<application.clients.length;i++) {
 application.clients[i].call("showServerMsg",application.clients.length);
}

本例题:一旦有客户机连接fms,就给每个连接的客户机广播,并显示出"已经有n位用户连接"

4. 服务器端呼叫服务器端
NetConnection.call
用法:
NetConnection.call(methodName, [resultObj, p1, ..., pN])
调用一个 Flash Communication Server 或者其他应用服务器上的命令或方法。用法和客户端的 NetConnection.call 的用法一样。他调用一个远程服务器上的方法。我就没贴代码