The basic concept of the AMF protocol is learned in XML text data. As I learned about this protocol, I found that its use is no longer limited to one method. It has also been presented in many other fields. Now let's get to know this agreement.
History of AMF Protocol
Actionmessage format (AMF) is an Adobe protocol used for data interaction and Remote Process calling. It is functionally equivalent to WebService, however, the difference between AMF and XML in WebService is that AMF is binary data while XML is text data, and AMF transmission efficiency is higher than XML. AMF uses HTTP transmission, currently, it is mainly used in ActionScript to implement communication between flex and server. Currently, there are two versions: amf0 and amf3.
Application diagram of AMF Protocol
Its content processing process:
1. Obtain the HTTP request stream from the client.
2. Stream deserialization (deserialize) to obtain data that can be recognized by the server program and establish a Response Message
3. Start debug
4. stream processing (record? License? Service) to get the return value
5. serialize the response stream
6. Send an HTTP Response to the client
The value of the flashactionscript data type in the AMF protocol is:
1. number 0x00;
2. boolean 0x01;
3. String 0x02;
4. Object 0x03;
5. movieclip 0x04;
6. null 0x05;
7. undefined 0x06;
8. Reference 0x07;
9. ecmaarray 0x08;
10. objectend 0x09;
11. strictarray 0x0a;
12. Date 0x0b;
13. longstring 0x0c;
14. Unsupported 0x0d;
15. recordset 0x0e;
16. xmlobject 0x0f;
17. typedobject (class) 0x10;
Features of AMF Protocol
The biggest feature of the AMF protocol is that flash built-in objects such as object, array, date, and XML can be directly transmitted back to the server and automatically parsed to appropriate objects on the server, this reduces the complexity of developers' work and saves development time. Because AMF uses binary encoding, this method can compress data highly, therefore, it is very suitable for transferring a large amount of data. The larger the data volume, the higher the transmission efficiency of flashremoting, far exceeds the WebService. XML, loadvars, and loadvariables () use plain text transmission methods, performance cannot be compared with Flash remoting 。
The reasons for dropping the communication between soap and Flash Player with AMF are as follows:
1. Soap processes data in XML format, which is too lengthy compared with the binary atom File System (AES;
2. AMF can serialize data more effectively, because the original intention of AMF protocol is to support the data type of Flash ActionScript, but soap is committed to providing more extensive use;
AMF has evolved from amf0 in the Flash MX era to amf3. amf3 is used as the default serialization format of the event 3.0 in flashplaye 9, amf0 is used as the serialization formats of the old versions of actionscript1.0 and 2.0. amf3 is more efficient in data transmission over the network than amf0. amf3 can transmit int and uint objects as integers, data Types supported by actionscript3.0 can be serialized, such as bytearray, XML, and iexternalizable 。
AMF (actionmessage format) is a binary format data type. The flash data is encoded by AMF over HTTP and then sent back to the server, the remoting adaptor on the server decodes the correct native object after receiving the information and submits it to the correct program for processing. The AMF protocol is widely used in addition to flashremoting and for localconnection and Flash Communication Server, its biggest feature is that flash native objects can be directly stored.
For example, an object, array, date, XML is returned to the server, and the server is automatically translated into an appropriate object. For example, when the flash array is returned to PhP, it is automatically converted to the associative array; the biggest benefit of this feature for developers is that they do not need to manually process the complicated work of serialization and deserialization, which is not only more accurate, at the same time, development also saves time. Because the AMF protocol is binary format and the encoding is highly compressed, It is very suitable for transmitting a large amount of data, according to the Flash orb website testing (mainly for Web
Service and flash remoting), when the amount of data is larger, the transmission efficiency of Flash remoting is higher, far beyond the performance of Web services. Therefore, we can also know that XML, loadvars, loadvariables and other transmission methods using Plaine textformat are naturally incomparable.
AMF Components
AMF files are divided into four parts: Preface (preamble), AMF header, AMF subject, and response of the subject. The first two bytes of the preface are used to describe the AMF version, currently, AMF has two versions: amf0 and amf3. if amf0 is used, the value is: 00. 3rd and 4th bytes use a 16-bit integer to indicate the number of AMF headers. Each AMF header consists of the following four parts:
UTF string indicates the header name
Boolean indicates whether the header is required.
Int32 indicates the length of the header, but it seems that this value is FF in many cases, it seems that this field is meaningless 。
The variable is a data type of the AMF protocol 。
After the header expression is complete, a 16-bit integer is followed to indicate the number of AMF subjects. After this number, it is the AMF entity 。
AMF consists of the following four parts:
UTF string-response indicates the request class and method or response result 。
UTF string-target is an identifier, which is used to implement the correspondence between requests and responses. The request corresponding to the response is found through the target. Generally, an auto-incrementing integer is used 。
Int32-indicates the length of the subject. This field is generally useless.
The variable indicates the data of the subject 。
The body response is an AMF response in the same format as the request body after the client sends an AMF request to the server. However, the content in the body response is different:
Response: The string 'null '.
Target: the target value of the Request plus "/onstatus", "onresult", or "/ondebugevents. "/onstatus" is prepared for runtime errors. We generally don't care about this. "/onresult" indicates that the request is called correctly. "/ondebugevents" is used for debugging, and you do not need to worry about it here. if the target of the request is '/1', the response of the body after successful call should be'/1/onresult '。
Data: The AMF protocol file object returned after the response 。