Index: src/XMPPConnection.m ================================================================== --- src/XMPPConnection.m +++ src/XMPPConnection.m @@ -253,16 +253,21 @@ stringWithCString: cDomainToASCII]; } @finally { free(cDomainToASCII); } - @try { - SRVLookup = [XMPPSRVLookup - lookupWithDomain: domainToASCII]; - enumerator = [SRVLookup objectEnumerator]; + SRVLookup = [XMPPSRVLookup + lookupWithDomain: domainToASCII]; + enumerator = [SRVLookup objectEnumerator]; - while ((candidate = [enumerator nextObject]) != nil) { + // If there are no SRV records connect via A/AAAA record + if ((candidate = [enumerator nextObject]) == nil) + [sock connectToHost: domainToASCII + port: port]; + // Iterate over SRV records + else { + do { @try { [sock connectToHost: [candidate target] port: [candidate port]]; break; } @catch (OFAddressTranslationFailedException @@ -269,18 +274,12 @@ *e) { [e release]; } @catch (OFConnectionFailedException *e) { [e release]; } - } - } @catch (OFAddressTranslationFailedException *e) { - [e release]; - } - - if (!candidate) - [sock connectToHost: domainToASCII - port: port]; + } while ((candidate = [enumerator nextObject]) != nil); + } } [self XMPP_startStream]; [pool release];