使用XMPP的iOS连接到ejabberd失败

使用XMPP的iOS连接到ejabberd失败

问题描述:

我正在使用 https://github.com/robbiehanson/XMPPFramework 连接到我自己的计算机ejabberd服务器,但协商后始终失败。

I'm using https://github.com/robbiehanson/XMPPFramework to connect to my own ejabberd server, but it always failed after negotiation.

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

here is the log I got: 2014-01-17 07:14:40.780 Chat[48246:70b] error: (null)

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

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

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

2014-01-17 07:14:46.076 Chat[48246:70b] socketDidConnect

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

2014-01-17 07:14:46.077 Chat[48246:70b] xmppStreamDidStartNegotiation

2014-01-17 07:14:51.799 Chat [48246:70b] xmppStreamDidDisconnect:Error Domain = GCDAsyncSocketErrorDomain代码= 7套接字已由远程对等关闭 UserInfo = 0x918d2e0 {NSLocalizedDescription =套接字已由远程关闭同行}

2014-01-17 07:14:51.799 Chat[48246:70b] xmppStreamDidDisconnect: Error Domain=GCDAsyncSocketErrorDomain Code=7 "Socket closed by remote peer" UserInfo=0x918d2e0 {NSLocalizedDescription=Socket closed by remote peer}

,这里是代码:


- (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);
}


检查解决方案是否在此处报告 https://github.com/robbiehanson/XMPPFramework/issues/131 解决了您的问题。

Check if the solution reported here https://github.com/robbiehanson/XMPPFramework/issues/131 solves your issue.


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

Generally when the server is closing the connection, you get this error/ Two reasons when the server closes the connection:


  1. 如果客户端闲置,则不会发送常规ping。

  2. 您从其他登录具有相同凭据的客户端,并且在服务器设置中具有以下设置:
    总是踢-如果存在资源冲突,请立即踢另一个资源。在服务器>服务器设置>资源策略中。

  1. You are not sending regular pings if the client idle.
  2. You are logging in from some different client with the same credentials, and in the server settings have the setting: Always kick - If there is a resource conflict, immediately kick the other resource. in Server>server settings>resource policy.