AMFPHP课程系列之认识AMF协议
AMFPHP教程系列之认识AMF协议
Action Message Format(AMF)
AMF是一个松散的基于SOAP(Simple Object Access Protocol,简单对象访问协议)的二进制格式。它主要用于在Adobe
Flash应用
程序
和数据
库之间交换数据通过RPC(远程过程调用).
每条AMF消息都含有一个主体含有错误和响应,它们被表达成一个As对象。
AMF是Flash Player6引入的,该版本被引用为AMF0.直到Flash Player9和As3.0(此时新的数据类型和语言样式使得产生一个更新称作AMF3)一直没有改动。
Data Types数据类型
AMF包含几个核心数据类型,它们总是存在于数据序列化的始终:
Byte-----一个简单的8位数据。这是最简单的传送数据方式。
Int--------一个16位的数字由2个连续字节组成。第一个字节较重要,第二个字节次重要。
MediumInt-----一个24位的数字类似上面的,仅仅长度的差别。
Long------一个32位的数字,同上,但更长。
Double---一个64位数字由8个连续的字节构成。代表一个浮点数有符号数字。double是按little-endian(低字节在后面?译者不确定呵呵)编码的。
UTF8---一个UTF8字符串长度小于2^16(65536)字节。它由一个整数(2个字节)表示字符串的长度,后面跟着UTF-8编码的字符串。
LongUTF8---一个UTF8字符串可能长于2^16字节。它由一个长整数(4字节)表示字符串长度,后面跟着utf8编码字符串。
?
Flash 5开始就可以以XML
或者“变量/值”配对输出格式向服务器传送数据。虽然这些数据能通过Flash编译
器自动解析或者通过开发
人员自行编写的代码手动解析, 但解析的速度慢。因为在解析过程中,XML需要按节点逐层处理数据。而且使用XML和“变量/值”配对格式处理的数据类型只能是字符型,数字也不例外。而Flash Remoting却能处理复杂数据类型, 比如对象
、结构、数组
,甚至可以是数据集,配合DataGrid
组件
可以很方便地显示数据。
为了处理复杂数据类型,采用一种独有的方式使Flash与应用
服务器间可以来回传送数据势在必行。于是AMF应运而生。AMF是Adobe
独家开发出来的通信
协议,它采用二进制压缩,序列化、反序列化、传输数据,从而为Flash 播放器
与Flash Remoting网关通信提供了一种轻量级的、高效能的通信方式。如下图所示。
AMF最大的特色在于可直接将Flash内置对象,例如Object, Array, Date,
XML,传回服务器端,并且在服务器端自动进行解析成适当的对象,这就减轻了开发人员繁复工作,同时也更省了开发时间。由于AMF采用二进制编码,这种方
式可以高度压缩数据,因此非常适合用来传递大量的资料。数据量越大,Flash Remoting的传输效能就越高,远远超过Web
Service。至于XML, LoadVars和loadVaria
bles() ,它们使用纯文本的传输方式,效能就更不能与Flash Remoting相提并论了。
注意:Flash Remoting需要浏览器支持Bin ary POST,Flash 播放器在Nets cape 6.x.环境下运行Flash Remoting会不起作用(Flash Remoting调用
没有效果
也不返回错误), Nets cape 7已经纠正了这个b u g 。对于早期Sa fari和Chim era版的苹果机也有这个问题。
同样是轻量级数据交换协议,同样是通过调用远程服务,同样是基于标准的HTTP和HTTPS协议, Flash Remoting为什么选择了使用AMF而放弃了SOAP与Flash 播放器通信呢??有如下原因:
SOAP将数据处理成XML格式,相对于二进制的AFM太冗长了;
AMF能更有效序列化数据;因为AMF的初衷只是为了支持Flash ActionScript的数据类型,而SOAP却致力于提供更广泛的用途;
AMF支持Flash 播放器 6只需要浏览器增加4 KB左右(压缩后)的大小,而SOAP就大多了;
SOAP的一些头部文件请求在Flash 播放器 6不支持。那Flash 播放器 6为什么能访问基于SOAP的Web服务呢?原来Flash
Remoting网关将SOAP请求在服务器端与转换成AFM格式,然后利用AFM与Flash 播放器通信。另外,AMF包中包含on
AMF从Flash MX时代的AMF0发展到现在的AMF3。AMF3用作Flash Playe 9的ActionScript 3.0的默认序列化格式,而AMF0则用作旧版的ActionScript 1.0和2.0的序列化格式。 在网络传输数据方面,AMF3比AMF0更有效率 。AMF3能将int和uint对象作为整数(integer)传输,并且能序列化ActionScript 3.0才支持的数据类型, 比如ByteArray,XML和Iexternalizable。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In the field of Web development, Web services are a very important technology that enable different applications to communicate with each other to build more complex and powerful systems. In this article, we will take an in-depth look at how to use PHP and SOAP to implement web service invocation and development. SOAP (SimpleObjectAccessProtocol) is an XML-based protocol used for information exchange between different applications. SOAP is an important Web service standard

PHP and SOAP: How to implement Remote Procedure Call (RPC) Introduction: In recent years, with the rise of distributed systems, Remote Procedure Call (RPC) has been widely adopted in Web development. This article will introduce how to implement RPC using PHP and SOAP, and demonstrate its usage through code examples. 1. What is remote procedure call (RPC)? Remote procedure call (RemoteProcedureCall, RPC) is a communication

PHP and SOAP: How to implement synchronous and asynchronous processing of data Introduction: In modern web applications, synchronous and asynchronous processing of data are becoming more and more important. Synchronous processing refers to processing only one request at a time and waiting for the completion of the request before processing the next request; asynchronous processing refers to processing multiple requests at the same time without waiting for the completion of a certain request. In this article, we will introduce how to use PHP and SOAP to achieve synchronous and asynchronous processing of data. 1. Introduction to SOAP SOAP (SimpleObject

Parsing SOAP messages using Python SOAP (Simple Object Access Protocol) is an XML-based remote procedure call (RPC) protocol used to communicate between different applications on the network. Python provides many libraries and tools to process SOAP messages, the most commonly used of which is the suds library. suds is a SOAP client library for Python that can be used to parse and generate SOAP messages. It provides a simple and

With the continuous development of Internet technology, more and more enterprise-level applications need to provide interfaces to other applications to realize the interaction of data and business. In this case, we need a reliable protocol to transmit data and ensure data integrity and security. SOAP (Simple Object Access Protocol) is an XML-based protocol that can be used to implement communication between applications in a Web environment. As a popular web programming language, PHP

Flash is a software used to create multimedia and interactive content, with features such as vector graphics, timeline animation, interactivity, and multimedia processing capabilities. Although once very popular, Flash was gradually phased out with the rise of new technologies, and official support ceased in 2020.

How to use PHP and SOAP to compress and decompress data Introduction: In modern Internet applications, data transmission is a very common operation. However, with the continuous development of Internet applications, the increase in data volume and the requirements for transmission speed, reasonable The use of data compression and decompression techniques has become a very important topic. In PHP development, we can use the SOAP (SimpleObjectAccessProtocol) protocol to achieve data compression and decompression. This article will show you how to

Flash used to be the king of online multimedia. Although its use has been greatly reduced now, in some old websites or specific applications, we still need Flash plug-ins. We will introduce in detail how to install Flash in Debian systems. What we need to be clear about is that Adobe has officially stopped supporting Flash Player on December 31, 2020. Therefore, the Flash version we recommend is the open source PepperFlash. PepperFlash is a Flash version developed by Google and specially used by the Chrome browser. Installation steps: 1. Open the terminal and update your package list: ````sqlsudoapt-getupdat
