Class XMPPTCPConnection
- All Implemented Interfaces:
XMPPConnection
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
protected class
Nested classes/interfaces inherited from class org.jivesoftware.smack.AbstractXMPPConnection
AbstractXMPPConnection.InterceptorWrapper, AbstractXMPPConnection.ListenerWrapper, AbstractXMPPConnection.SyncPointState
Nested classes/interfaces inherited from interface org.jivesoftware.smack.XMPPConnection
XMPPConnection.FromMode
-
Field Summary
Modifier and TypeFieldDescriptionprotected final XMPPTCPConnection.PacketReader
Protected access level because of unit test purposesprotected final XMPPTCPConnection.PacketWriter
Protected access level because of unit test purposesFields inherited from class org.jivesoftware.smack.AbstractXMPPConnection
ASYNC_BUT_ORDERED, authenticated, authenticatedConnectionInitiallyEstablishedTimestamp, closingStreamReceived, compressionHandler, connected, connectionCounterValue, connectionListeners, connectionLock, debugger, host, lastFeaturesReceived, outgoingStreamXmlEnvironment, port, reader, saslFeatureReceived, SMACK_REACTOR, streamFeatures, streamId, tlsHandled, user, wasAuthenticated, writer
-
Constructor Summary
ConstructorDescriptionXMPPTCPConnection
(CharSequence jid, String password) Creates a new XMPP connection over TCP.XMPPTCPConnection
(CharSequence username, String password, String serviceName) Creates a new XMPP connection over TCP.Creates a new XMPP connection over TCP (optionally using proxies). -
Method Summary
Modifier and TypeMethodDescriptionboolean
addRequestAckPredicate
(StanzaFilter predicate) Add a predicate for Stream Management acknowledgment requests.void
addStanzaAcknowledgedListener
(StanzaListener listener) Add a Stanza acknowledged listener.void
addStanzaDroppedListener
(StanzaListener listener) Add a Stanza dropped listener.addStanzaIdAcknowledgedListener
(String id, StanzaListener listener) Add a new Stanza ID acknowledged listener for the given ID.protected void
protected void
afterSuccessfulLogin
(boolean resumed) protected void
Establishes a connection to the XMPP server.Returns the local address currently in use for this connection.int
Get the maximum resumption time in seconds after which a managed stream can be resumed.void
Performs an unclean disconnect and shutdown of the connection.boolean
Returns true if the connection is disconnected by a Stream resumption via Stream Management is possible.boolean
Returns true if the connection to the server has successfully negotiated encryption.boolean
Returns true if Stream Management is supported by the server.boolean
Returns true if Stream Management was successfully negotiated with the server.boolean
Returns true if the stream is resumable.boolean
Returns true if network traffic is being compressed.protected void
loginInternal
(String username, String password, Resourcepart resource) void
Remove all predicates for Stream Management acknowledgment requests.void
Remove all stanza acknowledged listeners.void
Removes all Stanza ID acknowledged listeners.boolean
removeRequestAckPredicate
(StanzaFilter predicate) Remove the given predicate for Stream Management acknowledgment request.boolean
Remove the given Stanza acknowledged listener.boolean
removeStanzaDroppedListener
(StanzaListener listener) Remove the given Stanza dropped listener.Remove the Stanza ID acknowledged listener for the given ID.void
Send an unconditional Stream Management acknowledgement request to the server.protected void
sendInternal
(TopLevelStreamElement element) protected void
void
Send a unconditional Stream Management acknowledgment to the server.void
setBundleandDeferCallback
(BundleAndDeferCallback bundleAndDeferCallback) Set the bundle and defer callback used for this connection.static void
setDefaultBundleAndDeferCallback
(BundleAndDeferCallback defaultBundleAndDeferCallback) Set the default bundle and defer callback used for new connections.void
setPreferredResumptionTime
(int resumptionTime) Set the preferred resumption time in seconds.void
setUseStreamManagement
(boolean useSm) Set if Stream Management should be used if supported by the server.static void
setUseStreamManagementDefault
(boolean useSmDefault) Set if Stream Management should be used by default for new connections.static void
setUseStreamManagementResumptiodDefault
(boolean useSmResumptionDefault) Deprecated.void
setUseStreamManagementResumption
(boolean useSmResumption) Set if Stream Management resumption should be used if supported by the server.static void
setUseStreamManagementResumptionDefault
(boolean useSmResumptionDefault) Set if Stream Management resumption should be used by default for new connections.protected void
For unit testing purposesprotected void
shutdown()
Shuts the current connection down.boolean
Returns true if the stream was successfully resumed with help of Stream Management.protected void
protected void
protected void
Methods inherited from class org.jivesoftware.smack.AbstractXMPPConnection
addAsyncStanzaListener, addConnectionListener, addMessageInterceptor, addOneTimeSyncCallback, addPresenceInterceptor, addStanzaListener, addStanzaSendingListener, addStreamFeature, addSyncStanzaListener, afterSaslAuthenticationSuccess, asyncGo, asyncGoLimited, authenticate, bindResourceAndEstablishSession, buildNonzaCallback, callConnectionAuthenticatedListener, callConnectionConnectedListener, callConnectionConnectingListener, connect, createStanzaCollector, createStanzaCollector, createStanzaCollectorAndSend, createStanzaCollectorAndSend, disconnect, disconnect, firePacketSendingListeners, getAuthenticatedConnectionInitiallyEstablishedTimestamp, getConfiguration, getConnectionCounter, getConnectionLock, getFeature, getFromMode, getHost, getLastStanzaReceived, getParsingExceptionCallback, getPort, getReactor, getReplyTimeout, getSmackTlsContext, getStanzaFactory, getStreamId, getStreamOpen, getUsedSaslMechansism, getUser, getXMPPServiceDomain, hasCurrentConnectionException, hasFeature, initDebugger, initState, invokeStanzaCollectorsAndNotifyRecvListeners, isAnonymous, isAuthenticated, isConnected, isSaslAuthenticated, login, login, login, notifyConnectionError, notifyWaitingThreads, onStreamOpen, parseAndProcessNonza, parseAndProcessStanza, parseFeatures, parseFeaturesAndNotify, processStanza, registerIQRequestHandler, removeAsyncStanzaListener, removeConnectionListener, removeMessageInterceptor, removePresenceInterceptor, removeStanzaCollector, removeStanzaListener, removeStanzaSendingListener, removeSyncStanzaListener, schedule, sendAndWaitForResponse, sendAsync, sendAsync, sendIqRequestAndWaitForResponse, sendIqRequestAsync, sendIqRequestAsync, sendNonza, sendNonzaNonBlocking, sendStanza, sendStanzaNonBlocking, sendStreamOpen, setCurrentConnectionExceptionAndNotify, setFromMode, setMaxAsyncOperations, setParsingExceptionCallback, setReplyTimeout, setUnknownIqRequestReplyMode, setWasAuthenticated, throwNotConnectedExceptionIfAppropriate, toString, trySendStanza, trySendStanza, unregisterIQRequestHandler, unregisterIQRequestHandler, updateOutgoingStreamXmlEnvironmentOnStreamOpen, waitFor, waitForClosingStreamTagFromServer, waitForConditionOrThrowConnectionException
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.jivesoftware.smack.XMPPConnection
getFeature, hasFeature
-
Field Details
-
packetWriter
Protected access level because of unit test purposes -
packetReader
Protected access level because of unit test purposes
-
-
Constructor Details
-
XMPPTCPConnection
Creates a new XMPP connection over TCP (optionally using proxies).Note that XMPPTCPConnection constructors do not establish a connection to the server and you must call
AbstractXMPPConnection.connect()
.- Parameters:
config
- the connection configuration.
-
XMPPTCPConnection
Creates a new XMPP connection over TCP.Note that
jid
must be the bare JID, e.g. "user@example.org". More fine-grained control over the connection settings is available using theXMPPTCPConnection(XMPPTCPConnectionConfiguration)
constructor.- Parameters:
jid
- the bare JID used by the client.password
- the password or authentication token.- Throws:
XmppStringprepException
- if the provided string is invalid.
-
XMPPTCPConnection
public XMPPTCPConnection(CharSequence username, String password, String serviceName) throws XmppStringprepException Creates a new XMPP connection over TCP.This is the simplest constructor for connecting to an XMPP server. Alternatively, you can get fine-grained control over connection settings using the
XMPPTCPConnection(XMPPTCPConnectionConfiguration)
constructor.- Parameters:
username
- TODO javadoc me pleasepassword
- TODO javadoc me pleaseserviceName
- TODO javadoc me please- Throws:
XmppStringprepException
- if the provided string is invalid.
-
-
Method Details
-
throwNotConnectedExceptionIfAppropriate
protected void throwNotConnectedExceptionIfAppropriate() throws SmackException.NotConnectedException- Overrides:
throwNotConnectedExceptionIfAppropriate
in classAbstractXMPPConnection
- Throws:
SmackException.NotConnectedException
-
throwAlreadyConnectedExceptionIfAppropriate
protected void throwAlreadyConnectedExceptionIfAppropriate() throws SmackException.AlreadyConnectedException- Overrides:
throwAlreadyConnectedExceptionIfAppropriate
in classAbstractXMPPConnection
- Throws:
SmackException.AlreadyConnectedException
-
throwAlreadyLoggedInExceptionIfAppropriate
protected void throwAlreadyLoggedInExceptionIfAppropriate() throws SmackException.AlreadyLoggedInException- Overrides:
throwAlreadyLoggedInExceptionIfAppropriate
in classAbstractXMPPConnection
- Throws:
SmackException.AlreadyLoggedInException
-
afterSuccessfulLogin
protected void afterSuccessfulLogin(boolean resumed) throws SmackException.NotConnectedException, InterruptedException - Overrides:
afterSuccessfulLogin
in classAbstractXMPPConnection
- Throws:
SmackException.NotConnectedException
InterruptedException
-
loginInternal
protected void loginInternal(String username, String password, Resourcepart resource) throws XMPPException, SmackException, IOException, InterruptedException - Specified by:
loginInternal
in classAbstractXMPPConnection
- Throws:
XMPPException
SmackException
IOException
InterruptedException
-
isSecureConnection
Description copied from interface:XMPPConnection
Returns true if the connection to the server has successfully negotiated encryption.- Specified by:
isSecureConnection
in interfaceXMPPConnection
- Specified by:
isSecureConnection
in classAbstractXMPPConnection
- Returns:
- true if a secure connection to the server.
-
shutdown
Shuts the current connection down. After this method returns, the connection must be ready for re-use by connect.- Specified by:
shutdown
in classAbstractXMPPConnection
-
instantShutdown
Description copied from class:AbstractXMPPConnection
Performs an unclean disconnect and shutdown of the connection. Does not send a closing stream stanza.- Specified by:
instantShutdown
in classAbstractXMPPConnection
-
sendInternal
protected void sendInternal(TopLevelStreamElement element) throws SmackException.NotConnectedException, InterruptedException - Specified by:
sendInternal
in classAbstractXMPPConnection
- Throws:
SmackException.NotConnectedException
InterruptedException
-
sendNonBlockingInternal
protected void sendNonBlockingInternal(TopLevelStreamElement element) throws SmackException.NotConnectedException, SmackException.OutgoingQueueFullException - Specified by:
sendNonBlockingInternal
in classAbstractXMPPConnection
- Throws:
SmackException.NotConnectedException
SmackException.OutgoingQueueFullException
-
isUsingCompression
Description copied from interface:XMPPConnection
Returns true if network traffic is being compressed. When using stream compression network traffic can be reduced up to 90%. Therefore, stream compression is ideal when using a slow speed network connection. However, the server will need to use more CPU time in order to un/compress network data so under high load the server performance might be affected.- Specified by:
isUsingCompression
in interfaceXMPPConnection
- Specified by:
isUsingCompression
in classAbstractXMPPConnection
- Returns:
- true if network traffic is being compressed.
-
connectInternal
protected void connectInternal() throws SmackException, IOException, XMPPException, InterruptedExceptionEstablishes a connection to the XMPP server. It basically creates and maintains a socket connection to the server.Listeners will be preserved from a previous connection if the reconnection occurs after an abrupt termination.
- Specified by:
connectInternal
in classAbstractXMPPConnection
- Throws:
XMPPException
- if an error occurs while trying to establish the connection.SmackException
- if Smack detected an exceptional situation.IOException
- if an I/O error occurred.InterruptedException
- if the calling thread was interrupted.
-
setWriter
For unit testing purposes- Parameters:
writer
- TODO javadoc me please
-
afterFeaturesReceived
-
setUseStreamManagementDefault
Set if Stream Management should be used by default for new connections.- Parameters:
useSmDefault
- true to use Stream Management for new connections.
-
setUseStreamManagementResumptiodDefault
@Deprecated public static void setUseStreamManagementResumptiodDefault(boolean useSmResumptionDefault) Deprecated.usesetUseStreamManagementResumptionDefault(boolean)
instead.Set if Stream Management resumption should be used by default for new connections.- Parameters:
useSmResumptionDefault
- true to use Stream Management resumption for new connections.
-
setUseStreamManagementResumptionDefault
Set if Stream Management resumption should be used by default for new connections.- Parameters:
useSmResumptionDefault
- true to use Stream Management resumption for new connections.
-
setUseStreamManagement
Set if Stream Management should be used if supported by the server.- Parameters:
useSm
- true to use Stream Management.
-
setUseStreamManagementResumption
Set if Stream Management resumption should be used if supported by the server.- Parameters:
useSmResumption
- true to use Stream Management resumption.
-
setPreferredResumptionTime
Set the preferred resumption time in seconds.- Parameters:
resumptionTime
- the preferred resumption time in seconds
-
addRequestAckPredicate
Add a predicate for Stream Management acknowledgment requests.Those predicates are used to determine when a Stream Management acknowledgement request is send to the server. Some pre-defined predicates are found in the
org.jivesoftware.smack.sm.predicates
package.If not predicate is configured, the
Predicate.forMessagesOrAfter5Stanzas()
will be used.- Parameters:
predicate
- the predicate to add.- Returns:
- if the predicate was not already active.
-
removeRequestAckPredicate
Remove the given predicate for Stream Management acknowledgment request.- Parameters:
predicate
- the predicate to remove.- Returns:
- true if the predicate was removed.
-
removeAllRequestAckPredicates
Remove all predicates for Stream Management acknowledgment requests. -
requestSmAcknowledgement
public void requestSmAcknowledgement() throws StreamManagementException.StreamManagementNotEnabledException, SmackException.NotConnectedException, InterruptedExceptionSend an unconditional Stream Management acknowledgement request to the server.- Throws:
StreamManagementException.StreamManagementNotEnabledException
- if Stream Management is not enabled.SmackException.NotConnectedException
- if the connection is not connected.InterruptedException
- if the calling thread was interrupted.
-
sendSmAcknowledgement
public void sendSmAcknowledgement() throws StreamManagementException.StreamManagementNotEnabledException, SmackException.NotConnectedException, InterruptedExceptionSend a unconditional Stream Management acknowledgment to the server.See XEP-198: Stream Management ยง 4. Acks: "Either party MAY send an <a/> element at any time (e.g., after it has received a certain number of stanzas, or after a certain period of time), even if it has not received an <r/> element from the other party."
- Throws:
StreamManagementException.StreamManagementNotEnabledException
- if Stream Management is not enabled.SmackException.NotConnectedException
- if the connection is not connected.InterruptedException
- if the calling thread was interrupted.
-
addStanzaAcknowledgedListener
Add a Stanza acknowledged listener.Those listeners will be invoked every time a Stanza has been acknowledged by the server. The will not get automatically removed. Consider using
addStanzaIdAcknowledgedListener(String, StanzaListener)
when possible.- Parameters:
listener
- the listener to add.
-
removeStanzaAcknowledgedListener
Remove the given Stanza acknowledged listener.- Parameters:
listener
- the listener.- Returns:
- true if the listener was removed.
-
removeAllStanzaAcknowledgedListeners
Remove all stanza acknowledged listeners. -
addStanzaDroppedListener
Add a Stanza dropped listener.Those listeners will be invoked every time a Stanza has been dropped due to a failed SM resume. They will not get automatically removed. If at least one StanzaDroppedListener is configured, no attempt will be made to retransmit the Stanzas.
- Parameters:
listener
- the listener to add.- Since:
- 4.3.3
-
removeStanzaDroppedListener
Remove the given Stanza dropped listener.- Parameters:
listener
- the listener.- Returns:
- true if the listener was removed.
- Since:
- 4.3.3
-
addStanzaIdAcknowledgedListener
public StanzaListener addStanzaIdAcknowledgedListener(String id, StanzaListener listener) throws StreamManagementException.StreamManagementNotEnabledException Add a new Stanza ID acknowledged listener for the given ID.The listener will be invoked if the stanza with the given ID was acknowledged by the server. It will automatically be removed after the listener was run.
- Parameters:
id
- the stanza ID.listener
- the listener to invoke.- Returns:
- the previous listener for this stanza ID or null.
- Throws:
StreamManagementException.StreamManagementNotEnabledException
- if Stream Management is not enabled.
-
removeStanzaIdAcknowledgedListener
Remove the Stanza ID acknowledged listener for the given ID.- Parameters:
id
- the stanza ID.- Returns:
- true if the listener was found and removed, false otherwise.
-
removeAllStanzaIdAcknowledgedListeners
Removes all Stanza ID acknowledged listeners. -
isSmAvailable
Returns true if Stream Management is supported by the server.- Returns:
- true if Stream Management is supported by the server.
-
isSmEnabled
Returns true if Stream Management was successfully negotiated with the server.- Returns:
- true if Stream Management was negotiated.
-
streamWasResumed
Returns true if the stream was successfully resumed with help of Stream Management.- Returns:
- true if the stream was resumed.
-
isDisconnectedButSmResumptionPossible
Returns true if the connection is disconnected by a Stream resumption via Stream Management is possible.- Returns:
- true if disconnected but resumption possible.
-
isSmResumptionPossible
Returns true if the stream is resumable.- Returns:
- true if the stream is resumable.
-
getMaxSmResumptionTime
Get the maximum resumption time in seconds after which a managed stream can be resumed.This method will return
Integer.MAX_VALUE
if neither the client nor the server specify a maximum resumption time. Be aware of integer overflows when using this value, e.g. do not add arbitrary values to it without checking for overflows before.- Returns:
- the maximum resumption time in seconds or
Integer.MAX_VALUE
if none set.
-
setDefaultBundleAndDeferCallback
public static void setDefaultBundleAndDeferCallback(BundleAndDeferCallback defaultBundleAndDeferCallback) Set the default bundle and defer callback used for new connections.- Parameters:
defaultBundleAndDeferCallback
- TODO javadoc me please- Since:
- 4.1
- See Also:
-
setBundleandDeferCallback
Set the bundle and defer callback used for this connection.You can use
null
as argument to reset the callback. Outgoing stanzas will then no longer get deferred.- Parameters:
bundleAndDeferCallback
- the callback ornull
.- Since:
- 4.1
- See Also:
-
getLocalAddress
Returns the local address currently in use for this connection.- Returns:
- the local address
-
setUseStreamManagementResumptionDefault(boolean)
instead.