前面两篇文字叙述了RTMFP协议的握手流程,本篇文字接着叙述RTMFP协议连接流程,如下:
一.接收packet的处理,如下:
(1).读取marker值,UInt8 marker = packet.read8()|0xF0;此时marker的值为Marker==0xfd
(2).读取TimeSent和LastTimeRecv的值,_timeSent = packet.read16();
UInt16 timeEcho = packet.read16();
(3).读取TypeId值,UInt8 type = packet.available()>0 ? packet.read8() : 0xFF;
说明:此时type的值为0x10或者0x11,其中type==0x10表示正常请求,type==0x11表示特别请求,比如后面紧接着的
是stage请求.
(4)紧接依次读取flag,idFlow,stage,ack,如下:
flags = message.read8();
UInt64 idFlow = message.read7BitLongValue();
stage = message.read7BitLongValue()-1;
deltaNAck = message.read7BitLongValue()-1;
(5)读取数字签名signature,如下:
string signature;
message.readString8(signature);
说明:server会使用该数字签名与上面读取的idFlow为该client创建一个flow流,
如下:Flow* pFlow = createFlow(idFlow,signature);
(6)解析Method Name字段,这里可知Method Name的值为"connect",用于建立连接
(7)解析AMF Object对象,该对象包含一些与client相关的信息,如下:
AMFSimpleObject obj;
message.readSimpleObject(obj);//开始解析
message.startReferencing();
((URI&)peer.swfUrl) = obj.getString("swfUrl","");//swf路径
((URI&)peer.pageUrl) = obj.getString("pageUrl","");//page路径
((string&)peer.flashVersion) = obj.getString("flashVer","");//版本
(8)响应client,连接条件都满足,并建立连接,如下:
AMFObjectWriter response(writer.writeSuccessResponse("Connect.Success","Connection succeeded"));
response.write("objectEncoding",3.0);
accept = peer.onConnection(message,response);
二.Response packet包的结构如下:
1.其中AMF Object就是我们上述写的一些内容,比如,
response(writer.writeSuccessResponse("Connect.Success","Connection succeeded"));
response.write("objectEncoding",3.0);
即json格式的((“objectEncoding”,“3”),(“code”, “NetConnection.Connect.Success”))
2.其他的像TypeId,IdFlow就是connect request发送来的,这里不再赘述.
未完待续~~
转载请注明出处:山水间博客,http://blog.csdn.net/linyanwen99/article/details/8668952