1
votes

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

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 Chat[48246:70b] xmppStreamWillConnect

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

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 Code=7 "Socket closed by remote peer" UserInfo=0x918d2e0 {NSLocalizedDescription=Socket closed by remote peer}

and here is the code:


- (void)viewDidLoad
{
    [super viewDidLoad];

    self.stream = [[XMPPStream alloc] init];
    self.stream.myJID = [XMPPJID jidWithString:@"[email protected]"];
    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);
}
1
hey @disorderdev you solved this issue ....then put some code of it ...i have same problem ...Dhaval Bhadania

1 Answers

1
votes

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. 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.