A Remoting request from the client consists of a short preamble, headers, and bodys. The preamble contains basic information about the nature of the request. Headers can be used to request debugging information, send authentication info, tag transactions, etc. Bodies contain actual Remoting requests and responses. A single Remoting envelope can contain several requests; Remoting supports batching out of the box.
Client headers and bodies need not be responded to in a one-to-one manner. That is, a body or header may not require a response. Debug information is requested by a header but sent back as a body object. The response index is essential for Flash player to understand the response therefore.
The first two bytes of an AMF message are an unsigned short int. In PHP you can read this with the following code.
public function readUnsignedShort() {
$byte1 = $this→readByte();
$byte2 = $this→readByte();
return (($byte1 « 8) | $byte2);
}
The result indicates what type of Flash Player connected to the server.
Note that Flash Player 9 will always set the second byte to 0×03, regardless of whether the message was sent in AMF0 or AMF3.
The third and fourth bytes form an integer value that specifies the number of headers.
Each header consists of the following:
AMF headers may be user-created. However, certain headers have certain meaning that a gateway should respond to. See predefined headers for more information.
Between the headers and the start of the bodies is a int specifying the number of bodies. Each body consists of the following:
The target may be one of the following:
The response is a string that gives the body an id so it can be tracked by the player.
The response to a request has the exact same structure as a request. A request requiring a body response should be answered in the following way: