diff --git a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java index bd3d47554..530bf7b11 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java @@ -522,6 +522,9 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { closingStreamReceived = false; streamId = null; + // The connection should not be connected nor marked as such prior calling connectInternal(). + assert !connected; + try { // Perform the actual connection to the XMPP service connectInternal(); @@ -537,8 +540,9 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { throw e; } - // Make note of the fact that we're now connected. - connected = true; + // If connectInternal() did not throw, then this connection must now be marked as connected. + assert connected; + callConnectionConnectedListener(); return this; diff --git a/smack-core/src/main/java/org/jivesoftware/smack/c2s/ModularXmppClientToServerConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/c2s/ModularXmppClientToServerConnection.java index b099d49d3..5bc020c46 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/c2s/ModularXmppClientToServerConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/c2s/ModularXmppClientToServerConnection.java @@ -217,6 +217,7 @@ public final class ModularXmppClientToServerConnection extends AbstractXMPPConne @Override public void setTransport(XmppClientToServerTransport xmppTransport) { ModularXmppClientToServerConnection.this.activeTransport = xmppTransport; + ModularXmppClientToServerConnection.this.connected = true; } }; diff --git a/smack-core/src/main/java/org/jivesoftware/smack/c2s/internal/ModularXmppClientToServerConnectionInternal.java b/smack-core/src/main/java/org/jivesoftware/smack/c2s/internal/ModularXmppClientToServerConnectionInternal.java index 79c0d3d8c..0462307c1 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/c2s/internal/ModularXmppClientToServerConnectionInternal.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/c2s/internal/ModularXmppClientToServerConnectionInternal.java @@ -116,5 +116,11 @@ public abstract class ModularXmppClientToServerConnectionInternal { public abstract void setCompressionEnabled(boolean compressionEnabled); + /** + * Set the active transport (TCP, BOSH, WebSocket, …) to be used for the XMPP connection. Also marks the connection + * as connected. + * + * @param xmppTransport the active transport. + */ public abstract void setTransport(XmppClientToServerTransport xmppTransport); } 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 2dbb44a04..4e5ff2974 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 @@ -836,6 +836,8 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { // there is an error establishing the connection connectUsingConfiguration(); + connected = true; + // We connected successfully to the servers TCP port initConnection();