【问题标题】:XMPP IOS Openfire disconnected after sending elementXMPP IOS Openfire 在发送元素后断开连接
【发布时间】:2015-10-25 21:08:20
【问题描述】:

发送自定义元素后我断开连接。有没有办法?我的连接代码

  [self addDelegate:self delegateQueue:dispatch_get_main_queue()];

[self setHostName:@"bowerchat.com"];
[self setHostPort:5222];

self.myJID = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@@bowerchat.com",UD_getObj(@"myPhoneNumber")]];

NSError * error;
[self connectWithTimeout:300 error:&error];

断线问题

Domain=GCDAsyncSocketErrorDomain Code=7 "Socket closed by remote peer" 

发现问题后,我将@"type" 参数更改为@"type2",现在它正在工作...但我找不到原因?

-(void)sendMessageToServer:(NSDictionary*)paraDict{
NSString * userPhone = [[DBHelper sharedObject]getUserPhone:paraDict[@"friend_id"]];
NSXMLElement *a = [NSXMLElement elementWithName:@"request" xmlns:@"urn:xmpp:receipts"];
if(paraDict[@"type"] != nil){
NSMutableDictionary * k = [[NSMutableDictionary alloc]initWithDictionary:paraDict];

    NSString * typeValue = [k[@"type"]copy];
    [k removeObjectForKey:@"type"];
    [k setObject:typeValue forKey:@"type2"];

paraDict = k;
}
XMPPElement *e = [[XMPPElement alloc] initWithName:@"message"];
for(NSString * key in paraDict.allKeys){
    [e addAttributeWithName:key stringValue:paraDict[key]];
}
[e addAttributeWithName:@"to" stringValue:getJabberString(userPhone)];
[e addAttributeWithName:@"from" stringValue:getMyJabberString];
[e addChild:a];
NSLog(@"%@",[e attributesAsDictionary]);
[self sendElement:e];

}

【问题讨论】:

  • 您没有在此代码中显示任何自定义元素。您甚至没有显示与服务器或连接相关的任何内容,只是格式化 JID。您能否扩展/澄清您的问题?
  • 我发现了问题。问题是类型的attirube名称。如果有属性名称“type”会发生错误。为什么?
  • 请更新您的问题以显示导致问题的 XMPP 数据包。这是获得有意义的回复所必需的。
  • 已更新。@MickaëlRémond

标签: ios objective-c xmpp xmppframework


【解决方案1】:

消息类型属性内置于 XMPP 协议中。它在 XMPP 上具有精确的含义,您不能将所需的内容作为 type 消息属性的值。根据 XMPP RFC 中的定义,唯一可能的类型是:

  • 聊天
  • 错误
  • 群聊
  • 标题
  • 正常

您不能在消息类型中添加任何内容,或者实际上,否则服务器应该断开您的连接。

参考:http://xmpp.org/rfcs/rfc6121.html#message-syntax-type

【讨论】:

    【解决方案2】:

    Here 是关于如何将自定义数据添加到您的节的一个很好的指南:

    不要不要

    • <message><iq><presence> 元素上添加新属性。
    • 为节创建新的类型值。
    • 创建新的顶级元素。
    • 将您的自定义数据放入<message><body> 中。
    • <presence> 节中的<show> 元素创造新值(RFC 6121 section 4.7.2.1 中列出了允许的值)

    做:

    在您自己的命名空间中添加一个新的 XML 元素:

    <message
       from='romeo@montague.net/orchard'
       to='juliet@capulet.com/balcony'
       type='chat'>
       <data xmlns='https://example.im/my-awesome-new-xmpp-app'></data>
    </message>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-16
      相关资源
      最近更新 更多