diff --git a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java index 039a853db..d1db146cb 100644 --- a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java +++ b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java @@ -554,7 +554,6 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { if (socketFactory == null) { socketFactory = SocketFactory.getDefault(); } - socket = socketFactory.createSocket(); for (HostAddress hostAddress : hostAddresses) { Iterator inetAddresses = null; String host = hostAddress.getFQDN(); @@ -575,6 +574,10 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { continue; } innerloop: while (inetAddresses.hasNext()) { + // Create a *new* Socket before every connection attempt, i.e. connect() call, since Sockets are not + // re-usable after a failed connection attempt. See also SMACK-724. + socket = socketFactory.createSocket(); + final InetAddress inetAddress = inetAddresses.next(); final String inetAddressAndPort = inetAddress + " at port " + port; LOGGER.finer("Trying to establish TCP connection to " + inetAddressAndPort);