The preceding two articles describe the handshake process of the rtmfp protocol. This article describes the connection process of the rtmfp protocol, as follows:
1. Receive packet processing as follows:
(1) read the marker value. uint8 marker = packet. read8 () | 0xf0; the marker value is marker = 0xfd.
(2). Read the values of timesent and lasttimerecv, _ timesent = packet. read16 ();
Uint16 timeecho = packet. read16 ();
(3). Read the typeid value. uint8 type = packet. Available ()> 0? Packet. read8 (): 0xff;
Note: The value of type is 0x10 or 0x11. type = 0x10 indicates a normal request, and type = 0x11 indicates a special request. For example
Is a stage request.
(4) read the flag, IdFlow, stage, and ACK in sequence, as follows:
Flags = message. read8 ();
Uint64 IdFlow = message. read7bitlongvalue ();
Stage = message. read7bitlongvalue ()-1;
Deltanack = message. read7bitlongvalue ()-1;
(5) read the digital signature as follows:
String signature;
Message. readstring8 (signature );
Note: The server will use this digital signature to create a flow for the client with the IdFlow read above,
Flow * pflow = createflow (IdFlow, signature );
(6) parse the Method Name field. The value of method name is "Connect", which is used to establish a connection.
(7) parse the AMF object, which contains some client-related information, as follows:
Amfsimpleobject OBJ;
Message. readsimpleobject (OBJ); // start Parsing
Message. startreferencing ();
(Uri&#peer.swf URL) = obj. getstring ("swfurl", ""); // SWF path
(URI &) Peer. pageurl) = obj. getstring ("pageurl", ""); // page path
(String &) Peer. flashversion) = obj. getstring ("flashver", ""); // version
(8) Respond to the client, meet the connection conditions, and establish a connection, as shown below:
Amfobjectwriter response (writer. writesuccessresponse ("Connect. Success", "connection succeeded "));
Response. Write ("objectencoding", 3.0 );
Accept = peer. onconnection (message, response );
2. The structure of the response packet package is as follows:
1. AMF object is the content written above, for example,
Response (writer. writesuccessresponse ("Connect. Success", "connection succeeded "));
Response. Write ("objectencoding", 3.0 );
("Objectencoding", "3"), ("code", "netconnection. Connect. Success") in JSON format "))
2. For other types like typeid, IdFlow is sent by the CONNECT request, which is not described here.
Not complete to be continued ~~
Reprinted please indicate the source: zhujian blog, http://blog.csdn.net/linyanwen99/article/details/8668952