使用XMPP的iOS连接到ejabberd失败

我使用https://github.com/robbiehanson/XMPPFramework连接到我自己的ejabberd服务器,但经过协商后总是失败。

这里是我得到的日志:2014-01-17 07:14:40.780 Chat [48246:70b] error:(null)

2014-01-17 07:14:40.789 Chat [48246:70b] xmppStreamWillConnect

2014-01-17 07:14:46.0​​76 Chat [48246:70b] socketDidConnect

2014-01-17 07:14:46.0​​77 Chat [48246:70b] xmppStreamDidStartNegotiation

2014-01-17 07:14:51.799 Chat [48246:70b] xmppStreamDidDisconnect:错误域= GCDAsyncSocketErrorDomain代码= 7“由远程对等closures的套接字”UserInfo = 0x918d2e0 {NSLocalizedDescription =由远程对等closures的套接字}

这里是代码:

- (void)viewDidLoad { [super viewDidLoad]; self.stream = [[XMPPStream alloc] init]; self.stream.myJID = [XMPPJID jidWithString:@"test@gmail.com"]; self.stream.hostName = @"my host ip"; self.stream.hostPort = 5222; [self.stream addDelegate:self delegateQueue:dispatch_get_main_queue()]; self.reconnect = [[XMPPReconnect alloc] init]; [self.reconnect activate:self.stream]; self.muc = [[XMPPMUC alloc] init]; [self.muc activate:self.stream]; NSError *error = nil; if (![self.stream connectWithTimeout:XMPPStreamTimeoutNone error:&error]) { NSLog(@"error: %@", error); } NSLog(@"error: %@", error); } - (void)xmppStreamWillConnect:(XMPPStream *)sender { NSLog(@"xmppStreamWillConnect"); } - (void)xmppStream:(XMPPStream *)sender socketDidConnect:(GCDAsyncSocket *)socket { NSLog(@"socketDidConnect"); } - (void)xmppStreamDidStartNegotiation:(XMPPStream *)sender { NSLog(@"xmppStreamDidStartNegotiation"); } - (void)xmppStream:(XMPPStream *)sender willSecureWithSettings:(NSMutableDictionary *)settings { NSLog(@"willSecureWithSettings: %@", settings); } - (void)xmppStreamDidSecure:(XMPPStream *)sender { NSLog(@"xmppStreamDidSecure"); } - (void)xmppStreamDidConnect:(XMPPStream *)sender { NSLog(@"xmppStreamDidConnect"); NSError *error = nil; [self.stream authenticateAnonymously:&error]; NSLog(@"authenticate: %@", error); } - (void)xmppStreamDidRegister:(XMPPStream *)sender { NSLog(@"xmppStreamDidRegister"); } - (void)xmppStream:(XMPPStream *)sender didNotRegister:(NSXMLElement *)error { NSLog(@"didNotRegister: %@", error); } - (void)xmppStreamDidAuthenticate:(XMPPStream *)sender { NSLog(@"xmppStreamDidAuthenticate"); } - (void)xmppStream:(XMPPStream *)sender didNotAuthenticate:(NSXMLElement *)error { NSLog(@"didNotAuthenticate: %@", error); } - (void)xmppStreamWasToldToDisconnect:(XMPPStream *)sender { NSLog(@"xmppStreamWasToldToDisconnect"); } - (void)xmppStreamConnectDidTimeout:(XMPPStream *)sender { NSLog(@"xmppStreamConnectDidTimeout"); } - (void)xmppStreamDidDisconnect:(XMPPStream *)sender withError:(NSError *)error { NSLog(@"xmppStreamDidDisconnect: %@", error); } 

检查解决scheme是否报告在这里https://github.com/robbiehanson/XMPPFramework/issues/131解决您的问题。

通常,当服务器closures连接时,会出现此错误/服务器closures连接的两个原因:

  1. 如果客户闲置,您不会定期发送ping。
  2. 您使用相同的凭据从不同的客户端login,并在服务器设置中进行以下设置: 始终启动 – 如果存在资源冲突,请立即启动其他资源。 在服务器>服务器设置>资源策略中。