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:@"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);
}
Check if the solution reported here https://github.com/robbiehanson/XMPPFramework/issues/131 solves your issue.