We have explained the AMF protocol. I don't know if you have mastered it, and we also stressed the differences and differences between the two versions. Now we will continue to explain the relevant knowledge. Hope you can get help. Then, we need to encapsulate a complete AMF protocol file. The AMF file is generally divided into four parts: Preface (Preamble) the first two bytes in the preface are used to describe the AMF version. Currently, AMF has two versions: AMF0 and AMF3. if AMF0 is used, the response 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 Header length, but it seems that this value is FF in many cases, it seems that this field is meaningless 。
◆ The Variable is a certain AMF protocol data type 。
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. It is used to find the corresponding request through the Target to implement the correspondence between the request and the response. Generally, it uses an auto-incrementing integer 。
◆ 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 。
After talking about so many estimates, I still feel abstract. The following is an example: