Iterator<HostAddress> it = config.getHostAddresses().iterator();
List<HostAddress> failedAddresses = new LinkedList<HostAddress>();
boolean xmppIOError = false;
while (it.hasNext()) {
exception = null;
HostAddress hostAddress = it.next();
String host = hostAddress.getFQDN();
int port = hostAddress.getPort();
try {
if (config.getSocketFactory() == null) {
this.socket = new Socket(host, port);
}
else {
this.socket = config.getSocketFactory().createSocket(host, port);
}
} catch (UnknownHostException uhe) {
String errorMessage = "Could not connect to " + host + ":" + port + ".";
exception = new XMPPException(errorMessage, new XMPPError(XMPPError.Condition.remote_server_timeout,
errorMessage), uhe);
} catch (IOException ioe) {
String errorMessage = "XMPPError connecting to " + host + ":" + port + ".";
exception = new XMPPException(errorMessage, new XMPPError(XMPPError.Condition.remote_server_error,
errorMessage), ioe);
xmppIOError = true;
}
if (exception == null) {
// We found a host to connect to, break here
config.setUsedHostAddress(hostAddress);
break;
}
hostAddress.setException(exception);
failedAddresses.add(hostAddress);
if (!it.hasNext()) {
// There are no more host addresses to try
// throw an exception and report all tried
// HostAddresses in the exception