ios - 如何使用 libRTMP.a 将 AMFObject 发送到服务器
<p><p>我正在尝试使用 RTMP 开发聊天功能,所以我得到并编译了 libRTMP。</p>
<p>如何将 <code>NSDictionary</code> 发送到服务器?</p>
<p>我用的是<code>AMFObject</code>,但是Xcode编译的时候出错了。</p>
<pre><code> RTMPPacket packet;
char pbuf;
char *pend = pbuf + sizeof(pbuf);
char *enc;
//块流ID为4
packet.m_nChannel = 0x04; /* source channel (invoke) */
packet.m_headerType = RTMP_PACKET_SIZE_LARGE;
packet.m_packetType = RTMP_PACKET_TYPE_INVOKE;/* INVOKE */
packet.m_nTimeStamp = (uint32_t)[ timeIntervalSince1970];
//流ID
packet.m_nInfoField2 = sendRtmp->m_stream_id;
packet.m_hasAbsTimestamp = 0;
packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE;
//指向Chunk的负载
enc = packet.m_body;
/*组装方法*/
AVal methodName;
NSString *methodNameString = @"login1";
methodName.av_val = (char*);
methodName.av_len = (int)[ length];
//对“publish”字符串进行AMF编码
enc = AMF_EncodeString(enc, pend, &methodName);
enc = AMF_EncodeNumber(enc, pend, ++sendRtmp->m_numInvokes);
*enc++ = AMF_NULL;
struct AMFObject *object = (struct AMFObject *)malloc(sizeof(struct AMFObject));
struct AMFObjectProperty *property = (struct AMFObjectProperty *)malloc(sizeof(struct AMFObjectProperty));
/*key*/
AVal key;
NSString *keyString = @"name";
key.av_val = (char*);
key.av_len = (int)[ length];
/*value*/
AVal value;
NSString *valueString = @"liubo";
value.av_val = (char*);
value.av_len = (int)[ length];
AMFProp_SetName(property, &key);
AMFProp_SetString(property, &value);
AMF_AddProp(object, property);
AMF_Encode(object, enc, pend);
enc = AMF_EncodeNumber(enc, pend, ++sendRtmp->m_numInvokes);
*enc++ = AMF_NULL;
free(object);
free(property);
if (!enc)
return;
packet.m_nBodySize = enc - packet.m_body;
int code = RTMP_SendPacket(sendRtmp, &packet, TRUE);
NSLog(@"发送消息完毕:%@返回值:%d",message,code);
</code></pre>
<p>Xcode编译时出现错误:</p>
<p> <img src="/image/qtthC.png" alt="enter image description here"/> </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我在 iOS 上发现了与 AMFProp_SetString 相同的错误。我以这种方式添加属性:</p>
<pre><code>AMFObject object;
object.o_props = malloc(sizeof(AMFObjectProperty *)); // Needs a malloc for AMF_AddProp
AMFObjectProperty prop;
AVal name = AVC("test");
AVal nothing = AVC("");
prop.p_type = AMF_STRING;
prop.p_vu.p_aval = name;
prop.p_name = nothing;
object.o_num = 0;
AMF_AddProp(&object, &prop);
</code></pre>
<p>希望对你有帮助。</p></p>
<p style="font-size: 20px;">关于ios - 如何使用 libRTMP.a 将 AMFObject 发送到服务器,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/29693711/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/29693711/
</a>
</p>
页:
[1]