接著客戶端傳送54bytes的數據 Deserialize來解碼得到的消息是,此時消耗掉4bytes [cpp] case RM_HEADER_MESSAGETYPE_WINACKSIZE: { return DeserializeWinAckSize(buffer, message[RM_WINACKSIZE]); } 得到應答是25000000 所以回復 [cpp] case RM_HEADER_MESSAGETYPE_WINACKSIZE: { return ProcessWinAckSize(pFrom, request); } [cpp] bool BaseRTMPAppProtocolHandler::ProcessWinAckSize(BaseRTMPProtocol *pFrom, Variant &request) { if (request[RM_WINACKSIZE] != _V_NUMERIC) { FATAL("Invalid message: %s", STR(request.ToString())); return false; } uint32_t size = (uint32_t) request[RM_WINACKSIZE]; if ((size > 4 * 1024 * 1024) || size == 0) { FATAL("Invalid message: %s", STR(request.ToString())); return false; } pFrom->SetWinAckSize(request[RM_WINACKSIZE]); return true; } 已經從54bytes中去掉了12+4bytes還剩38 再去掉12bytes,還剩下26bytes Deserialize來解碼得到的消息是(此時這裡把剩下的26bytes消耗完全) [cpp] case RM_HEADER_MESSAGETYPE_FLEX: { message[RM_INVOKE][RM_INVOKE_IS_FLEX] = (bool)(H_MT(header) == RM_HEADER_MESSAGETYPE_FLEX); return DeserializeInvoke(buffer, message[RM_INVOKE]); } 在下面進行消息的處理(回應) [cpp] bool RTMPProtocolSerializer::DeserializeInvoke(IOBuffer &buffer, Variant &message) { if (message[RM_INVOKE_IS_FLEX]) { if (!buffer.Ignore(1)) { FATAL("Unable to ignore 1 byte"); return false; } } if (!_amf0.ReadShortString(buffer, message[RM_INVOKE_FUNCTION])) { FATAL("Unable to read %s", STR(RM_INVOKE_FUNCTION)); return false; } if (!_amf0.ReadDouble(buffer, message[RM_INVOKE_ID])) { FATAL("Unable to read %s", STR(RM_INVOKE_ID)); return false; } for (uint32_t i = 0; GETAVAILABLEBYTESCOUNT(buffer) > 0; i++) { if (!_amf0.Read(buffer, message[RM_INVOKE_PARAMS][i])) { FATAL("Unable to de-serialize invoke parameter %u", i); return false; } } return true; } [cpp] bool BaseRTMPAppProtocolHandler::InboundMessageAvailable(BaseRTMPProtocol *pFrom, Variant &request) { case RM_HEADER_MESSAGETYPE_FLEX: { return ProcessInvoke(pFrom, request); 這裡主要是處理ProcessInvokeCreateStream } } [cpp] bool BaseRTMPAppProtocolHandler::ProcessInvokeCreateStream(BaseRTMPProtocol *pFrom, Variant &request) { uint32_t id = 0; //1. Create the neutral stream if (pFrom->CreateNeutralStream(id) == NULL) { FATAL("Unable to create stream"); return false; } //2. Send the response Variant response = StreamMessageFactory::GetInvokeCreateStreamResult(request, id); return SendRTMPMessage(pFrom, response); } 到了這裡數據就處理完了,一共發送了37bytes的數據給client