ios – 无法创建xmpp muc room:代码503(服务不可用)

ios – 无法创建xmpp muc room:代码503(服务不可用),第1张

概述我创建房间的代码: XMPPRoomCoreDataStorage *rosterstorage = [[XMPPRoomCoreDataStorage alloc] init];XMPPRoom *xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:rosterstorage jid:[XMPPJID jidWithString:@"groupch 我创建房间的代码:
XMPPRoomCoreDataStorage *rosterstorage = [[XMPPRoomCoreDataStorage alloc] init];XMPPRoom *xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:rosterstorage jID:[XMPPJID jIDWithString:@"groupchat@xmpp.getkismet.com/groupchat"] dispatchQueue:dispatch_get_main_queue()];[xmppRoom activate:[[self appDelegate] xmppStream]];if ([xmppRoom preJoinWithNickname:@"nameToCreateRoom"]) {    NSLog(@"room created");    [xmppRoom joinRoomUsingNickname:self.username history:nil];}[xmppRoom fetchConfigurationForm];[xmppRoom configureRoomUsingOptions:nil];[xmppRoom addDelegate:[self appDelegate] delegateQueue:dispatch_get_main_queue()];

调试:

2012-08-03 07:46:29.204 iPhoneXMPP[9887:fb03] room created2012-08-03 07:46:29:230 iPhoneXMPP[9887:15003] SEND: <iq type="get" to="groupchat@xmpp.getkismet.com" ID="B793062B-0E09-492F-BC0F-703503AAA664"><query xmlns="http://jabber.org/protocol/muc#owner"/></iq>2012-08-03 07:46:29:237 iPhoneXMPP[9887:15003] SEND: <iq type="set" to="groupchat@xmpp.getkismet.com" ID="392D5BFC-707B-4F68-A829-56F949F4E96D"><query xmlns="http://jabber.org/protocol/muc#owner"><x xmlns="jabber:x:data" type="submit"/></query></iq>2012-08-03 07:46:29:326 iPhoneXMPP[9887:14f03] SEND: <presence to="groupchat@xmpp.getkismet.com"><x xmlns="http://jabber.org/protocol/muc"/><x xmlns="vcard-temp:x:update"><photo>91217a961321f8f6380ea2feefd0632353ad296c</photo></x><c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="http://code.Google.com/p/xmppframework" ver="VyOFcFX6+YNmKssVXSBKGFP0BS4="/></presence>2012-08-03 07:46:29:327 iPhoneXMPP[9887:14f03] RECV: <iq xmlns="jabber:clIEnt" from="groupchat@xmpp.getkismet.com" to="lee@xmpp.getkismet.com/41068195801343976386548353" type="error" ID="B793062B-0E09-492F-BC0F-703503AAA664"><query xmlns="http://jabber.org/protocol/muc#owner"/><error code="503" type="cancel"><service-unavailable xmlns="urn:IEtf:params:xml:ns:xmpp-stanzas"/></error></iq>2012-08-03 07:46:29:343 iPhoneXMPP[9887:fb03] iPhoneXMPPAppDelegate: xmppStream:dIDReceiveIQ:2012-08-03 07:46:29:421 iPhoneXMPP[9887:15003] RECV: <iq xmlns="jabber:clIEnt" from="groupchat@xmpp.getkismet.com" to="lee@xmpp.getkismet.com/41068195801343976386548353" type="error" ID="392D5BFC-707B-4F68-A829-56F949F4E96D"><query xmlns="http://jabber.org/protocol/muc#owner"><x xmlns="jabber:x:data" type="submit"/></query><error code="503" type="cancel"><service-unavailable xmlns="urn:IEtf:params:xml:ns:xmpp-stanzas"/></error></iq>2012-08-03 07:46:29:440 iPhoneXMPP[9887:fb03] iPhoneXMPPAppDelegate: xmppStream:dIDReceiveIQ:

我看到它正在创建/加入groupchat@xmpp.getkismet.com而不是像我指定的groupchat@xmpp.getkismet.com/groupchat.我读到这很可能是问题所在.但是,我已经指定了完整的jID,所以我迷路了.

在此先感谢所有帮助的人.

解决方法 首先,请看一下 XEP-0045: Multi-User Chat.如您所见,首先您必须发现您的用户(XMPPJID)在Jabber服务器上具有哪些功能.为此,请将下一个命令发送到您的Jabber服务器:
<iq from='user@jabber.server.com/resource' ID='some_Expression' to='jabber.server.com' type='get'>    <query xmlns='http://jabber.org/protocol/disco#items'/></iq>

或使用XMPP库函数在objective-c中写入:

NSError *error = nil;NSXMLElement *query = [[NSXMLElement alloc] initWithXMLString:@"<query xmlns='http://jabber.org/protocol/disco#items'/>"                                                         error:&error];XMPPIQ *iq = [XMPPIQ iqWithType:@"get"                              to:[XMPPJID jIDWithString:@"jabber.server.com"]                       elementID:[xmppStream generateUUID] child:query];[xmppStream sendElement:iq];

现在在XMPPStream委托中侦听来自服务器的响应 – (BOol)xmppStream:(XMPPStream *)sender dIDReceiveIQ:(XMPPIQ *)iq和服务器响应应该是这样的:

<iq from='jabber.server.com' ID='some_Expression' to='user@jabber.server.com/resource' type='result'>    <query xmlns='http://jabber.org/protocol/disco#items'>        <item jID='im.jabber.server.com' name='Instant Message Service'/>        <item jID='conference.jabber.server.com' name='Chatroom Service'/>    </query></iq>

或目标c:

- (BOol)xmppStream:(XMPPStream *)sender dIDReceiveIQ:(XMPPIQ *)iq{    if([iq isResultIQ])    {        if([iq elementForname:@"query" xmlns:@"http://jabber.org/protocol/disco#items"])        {            NSLog(@"Jabber Server's CapabilitIEs: %@",[iq XMLString]);        }    }}

现在,对于返回的每个项目,将IQ发送到您的服务器以获取它的属性,并确定哪个是会议类型,如下所示:

<iq from='user@jabber.server.com/resource' ID='some_Expression' to='conference.jabber.server.com' type='get'>    <query xmlns='http://jabber.org/protocol/disco#info'/></iq>

或在目标c:

- (BOol)xmppStream:(XMPPStream *)sender dIDReceiveIQ:(XMPPIQ *)iq{    if([iq isResultIQ])    {        if([iq elementForname:@"query" xmlns:@"http://jabber.org/protocol/disco#items"])        {            NSXMLElement *query = [iq childElement];            NSArray *items = [query children];            for(NSXMLElement *item in items)            {                NSError *error = nil;                NSXMLElement *sendquery = [[NSXMLElement alloc] initWithXMLString:@"<query xmlns='http://jabber.org/protocol/disco#info'/>"                                                                             error:&error];                XMPPIQ *sendIQ = [XMPPIQ iqWithType:@"get"                                                  to:[XMPPJID jIDWithString:[item attributeStringValueForname:@"jID"]]                                           elementID:[xmppStream generateUUID]                                               child:sendquery];                [xmppStream sendElement:sendIQ];            }        }    }}

听取服务器的回复:

<iq from='conference.jabber.server.com' ID='some_Expression' to='user@jabber.server.com/resource' type='result'>    <query xmlns='http://jabber.org/protocol/disco#info'>        <IDentity category='conference' name='Server Group Chat Service' type='text'/>        <feature var='http://jabber.org/protocol/muc'/>    </query></iq>

并从类别:会议中识别群组聊天域名

- (BOol)xmppStream:(XMPPStream *)sender dIDReceiveIQ:(XMPPIQ *)iq{    if([iq isResultIQ])    {        if([iq elementForname:@"query" xmlns:@"http://jabber.org/protocol/disco#items"])        {            ...        }        else if([iq elementForname:@"query" xmlns:@"http://jabber.org/protocol/disco#info"])        {            NSXMLElement *query = [iq childElement];            NSXMLElement *IDentity = [query elementForname:@"IDentity"];            if([[IDentity attributeStringValueForname:@"category"] isEqualToString:@"conference"])            {                groupChatDomain = [iq fromStr];            }        }    }}

最后,当我们获得群聊字段时,我们可以创建如下的聊天室:

XMPPJID *chatRoomJID = [XMPPJID jIDWithUser:@"chat_room"                                      domain:groupChatDomain                                    resource:@"user"];XMPPRoomMemoryStorage *roomMemoryStorage = [[XMPPRoomMemoryStorage alloc] init];XMPPRoom *xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:roomMemoryStorage                                                       jID:roomChatJID                                             dispatchQueue:dispatch_get_main_queue()];[xmppRoom activate:xmppStream];[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];[xmppRoom joinRoomUsingNickname:user history:nil];

并添加< XMPPRoomDelegate>视图控制器及其委托中的协议:

- (voID)xmppRoomDIDCreate:(XMPPRoom *)sender- (voID)xmppRoomDIDDestroy:(XMPPRoom *)sender- (voID)xmppRoom:(XMPPRoom *)sender dIDConfigure:(XMPPIQ *)iqresult- (voID)xmppRoom:(XMPPRoom *)sender dIDNotConfigure:(XMPPIQ *)iqresult- (voID)xmppRoomDIDJoin:(XMPPRoom *)sender- (voID)xmppRoomDIDLeave:(XMPPRoom *)sender- (voID)xmppRoom:(XMPPRoom *)sender occupantDIDJoin:(XMPPJID *)occupantJID withPresence:(XMPPPresence *)presence- (voID)xmppRoom:(XMPPRoom *)sender occupantDIDLeave:(XMPPJID *)occupantJID withPresence:(XMPPPresence *)presence- (voID)xmppRoom:(XMPPRoom *)sender dIDReceiveMessage:(XMPPMessage *)message fromOccupant:(XMPPJID *)occupantJID

注意:在邀请其他用户访问聊天室之前,您必须发送并确认房间配置(可以邀请其他用户,但无法发送消息).所以你可以在创建Room之后(委托 – (voID)xmppRoomDIDCreate 总结

以上是内存溢出为你收集整理的ios – 无法创建xmpp muc room:代码503(服务不可用)全部内容,希望文章能够帮你解决ios – 无法创建xmpp muc room:代码503(服务不可用)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1102129.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存