public class XMPPTCPConnection
extends org.jivesoftware.smack.AbstractXMPPConnection
XMPPConnection| Modifier and Type | Class and Description |
|---|---|
protected class |
XMPPTCPConnection.PacketReader |
protected class |
XMPPTCPConnection.PacketWriter |
| Modifier and Type | Field and Description |
|---|---|
protected XMPPTCPConnection.PacketReader |
packetReader
Protected access level because of unit test purposes
|
protected XMPPTCPConnection.PacketWriter |
packetWriter
Protected access level because of unit test purposes
|
authenticated, compressionHandler, config, connected, connectionCounterValue, connectionListeners, connectionLock, debugger, host, lastFeaturesReceived, port, reader, saslAuthentication, saslFeatureReceived, streamFeatures, user, wasAuthenticated, writer| Constructor and Description |
|---|
XMPPTCPConnection(org.jivesoftware.smack.ConnectionConfiguration config)
Creates a new XMPP connection in the same way
XMPPTCPConnection(ConnectionConfiguration,CallbackHandler) does, but
with no callback handler for password prompting of the keystore. |
XMPPTCPConnection(org.jivesoftware.smack.ConnectionConfiguration config,
javax.security.auth.callback.CallbackHandler callbackHandler)
Creates a new XMPP connection using the specified connection configuration.
|
XMPPTCPConnection(java.lang.String serviceName)
Creates a new XMPP connection in the same way
XMPPTCPConnection(String,CallbackHandler) does, but
with no callback handler for password prompting of the keystore. |
XMPPTCPConnection(java.lang.String serviceName,
javax.security.auth.callback.CallbackHandler callbackHandler)
Creates a new connection to the specified XMPP server.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
addRequestAckPredicate(org.jivesoftware.smack.filter.PacketFilter predicate)
Add a predicate for Stream Management acknowledgment requests.
|
void |
addStanzaAcknowledgedListener(org.jivesoftware.smack.PacketListener listener)
Add a Stanza acknowledged listener.
|
org.jivesoftware.smack.PacketListener |
addStanzaIdAcknowledgedListener(java.lang.String id,
org.jivesoftware.smack.PacketListener listener)
Add a new Stanza ID acknowledged listener for the given ID.
|
protected void |
afterFeaturesReceived() |
protected void |
connectInternal()
Establishes a connection to the XMPP server and performs an automatic login
only if the previous connection state was logged (authenticated).
|
java.lang.String |
getConnectionID() |
org.jivesoftware.smack.parsing.ParsingExceptionCallback |
getParsingExceptionCallback()
Get the current active parsing exception callback.
|
void |
instantShutdown()
Performs an unclean disconnect and shutdown of the connection.
|
boolean |
isDisconnectedButSmResumptionPossible()
Returns true if the connection is disconnected by a Stream resumption via Stream Management is possible.
|
boolean |
isSecureConnection() |
boolean |
isSmAvailable()
Returns true if Stream Management is supported by the server.
|
boolean |
isSmEnabled()
Returns true if Stream Management was successfully negotiated with the server.
|
boolean |
isSmResumptionPossible()
Returns true if the stream is resumable.
|
boolean |
isSocketClosed() |
boolean |
isUsingCompression() |
void |
login(java.lang.String username,
java.lang.String password,
java.lang.String resource) |
void |
loginAnonymously() |
void |
removeAllRequestAckPredicates()
Remove all predicates for Stream Management acknowledgment requests.
|
void |
removeAllStanzaAcknowledgedListeners()
Remove all stanza acknowledged listeners.
|
void |
removeAllStanzaIdAcknowledgedListeners()
Removes all Stanza ID acknowledged listeners.
|
boolean |
removeRequestAckPredicate(org.jivesoftware.smack.filter.PacketFilter predicate)
Remove the given predicate for Stream Management acknowledgment request.
|
boolean |
removeStanzaAcknowledgedListener(org.jivesoftware.smack.PacketListener listener)
Remove the given Stanza acknowledged listener.
|
org.jivesoftware.smack.PacketListener |
removeStanzaIdAcknowledgedListener(java.lang.String id)
Remove the Stanza ID acknowledged listener for the given ID.
|
void |
requestSmAcknowledgement()
Send an unconditional Stream Management acknowledgement request to the server.
|
void |
send(org.jivesoftware.smack.packet.PlainStreamElement element) |
protected void |
sendPacketInternal(org.jivesoftware.smack.packet.Packet packet) |
void |
sendSmAcknowledgement()
Send a unconditional Stream Management acknowledgment to the server.
|
void |
setParsingExceptionCallback(org.jivesoftware.smack.parsing.ParsingExceptionCallback callback)
Install a parsing exception callback, which will be invoked once an exception is encountered while parsing a
stanza
|
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)
Set if Stream Management resumption should be used by default for new connections.
|
void |
setUseStreamManagementResumption(boolean useSmResumption)
Set if Stream Management resumption should be used if supported by the server.
|
protected void |
setWriter(java.io.Writer writer)
For unit testing purposes
|
protected void |
shutdown()
Shuts the current connection down.
|
addConnectionListener, addPacketInterceptor, addPacketListener, addPacketSendingListener, afterSuccessfulLogin, bindResourceAndEstablishSession, callConnectionAuthenticatedListener, callConnectionClosedOnErrorListener, callConnectionConnectedListener, connect, createPacketCollector, createPacketCollectorAndSend, createPacketCollectorAndSend, disconnect, disconnect, finalize, firePacketSendingListeners, getConfiguration, getConnectionCounter, getConnectionCreationListeners, getConnectionListeners, getConnectionLock, getFeature, getFromMode, getHost, getLastStanzaReceived, getPacketReplyTimeout, getPort, getRoster, getRosterStore, getSASLAuthentication, getServiceName, getUser, hasFeature, initDebugger, invokePacketCollectorsAndNotifyRecvListeners, isAnonymous, isAuthenticated, isConnected, isRosterLoadedAtLogin, login, maybeResolveDns, parseFeatures, processPacket, removeConnectionListener, removePacketCollector, removePacketInterceptor, removePacketListener, removePacketSendingListener, reportStanzaReceived, sendIqWithResponseCallback, sendIqWithResponseCallback, sendIqWithResponseCallback, sendPacket, sendStanzaWithResponseCallback, sendStanzaWithResponseCallback, sendStanzaWithResponseCallback, setFromMode, setLoginInfo, setPacketReplyTimeout, setServiceName, setWasAuthenticatedprotected XMPPTCPConnection.PacketWriter packetWriter
protected XMPPTCPConnection.PacketReader packetReader
public XMPPTCPConnection(java.lang.String serviceName,
javax.security.auth.callback.CallbackHandler callbackHandler)
This is the simplest constructor for connecting to an XMPP server. Alternatively, you can get fine-grained control over connection settings using the
XMPPTCPConnection(ConnectionConfiguration) constructor.Note that XMPPTCPConnection constructors do not establish a connection to the server and you must call
AbstractXMPPConnection.connect().The CallbackHandler will only be used if the connection requires the client provide an SSL certificate to the server. The CallbackHandler must handle the PasswordCallback to prompt for a password to unlock the keystore containing the SSL certificate.
serviceName - the name of the XMPP server to connect to; e.g. example.com.callbackHandler - the CallbackHandler used to prompt for the password to the keystore.public XMPPTCPConnection(java.lang.String serviceName)
XMPPTCPConnection(String,CallbackHandler) does, but
with no callback handler for password prompting of the keystore. This will work
in most cases, provided the client is not required to provide a certificate to
the server.serviceName - the name of the XMPP server to connect to; e.g. example.com.public XMPPTCPConnection(org.jivesoftware.smack.ConnectionConfiguration config)
XMPPTCPConnection(ConnectionConfiguration,CallbackHandler) does, but
with no callback handler for password prompting of the keystore. This will work
in most cases, provided the client is not required to provide a certificate to
the server.config - the connection configuration.public XMPPTCPConnection(org.jivesoftware.smack.ConnectionConfiguration config,
javax.security.auth.callback.CallbackHandler callbackHandler)
Manually specifying connection configuration information is suitable for advanced users of the API. In many cases, using the
XMPPTCPConnection(String) constructor is a better approach.Note that XMPPTCPConnection constructors do not establish a connection to the server and you must call
AbstractXMPPConnection.connect().The CallbackHandler will only be used if the connection requires the client provide an SSL certificate to the server. The CallbackHandler must handle the PasswordCallback to prompt for a password to unlock the keystore containing the SSL certificate.
config - the connection configuration.callbackHandler - the CallbackHandler used to prompt for the password to the keystore.public java.lang.String getConnectionID()
getConnectionID in interface org.jivesoftware.smack.XMPPConnectiongetConnectionID in class org.jivesoftware.smack.AbstractXMPPConnectionpublic void setParsingExceptionCallback(org.jivesoftware.smack.parsing.ParsingExceptionCallback callback)
callback - the callback to installpublic org.jivesoftware.smack.parsing.ParsingExceptionCallback getParsingExceptionCallback()
public void login(java.lang.String username,
java.lang.String password,
java.lang.String resource)
throws org.jivesoftware.smack.XMPPException,
org.jivesoftware.smack.SmackException,
java.io.IOException
login in class org.jivesoftware.smack.AbstractXMPPConnectionorg.jivesoftware.smack.XMPPExceptionorg.jivesoftware.smack.SmackExceptionjava.io.IOExceptionpublic void loginAnonymously()
throws org.jivesoftware.smack.XMPPException,
org.jivesoftware.smack.SmackException,
java.io.IOException
loginAnonymously in class org.jivesoftware.smack.AbstractXMPPConnectionorg.jivesoftware.smack.XMPPExceptionorg.jivesoftware.smack.SmackExceptionjava.io.IOExceptionpublic boolean isSecureConnection()
isSecureConnection in interface org.jivesoftware.smack.XMPPConnectionisSecureConnection in class org.jivesoftware.smack.AbstractXMPPConnectionpublic boolean isSocketClosed()
protected void shutdown()
shutdown in class org.jivesoftware.smack.AbstractXMPPConnectionpublic void instantShutdown()
public void send(org.jivesoftware.smack.packet.PlainStreamElement element)
throws org.jivesoftware.smack.SmackException.NotConnectedException
send in interface org.jivesoftware.smack.XMPPConnectionsend in class org.jivesoftware.smack.AbstractXMPPConnectionorg.jivesoftware.smack.SmackException.NotConnectedExceptionprotected void sendPacketInternal(org.jivesoftware.smack.packet.Packet packet)
throws org.jivesoftware.smack.SmackException.NotConnectedException
sendPacketInternal in class org.jivesoftware.smack.AbstractXMPPConnectionorg.jivesoftware.smack.SmackException.NotConnectedExceptionpublic boolean isUsingCompression()
isUsingCompression in interface org.jivesoftware.smack.XMPPConnectionisUsingCompression in class org.jivesoftware.smack.AbstractXMPPConnectionprotected void connectInternal()
throws org.jivesoftware.smack.SmackException,
java.io.IOException,
org.jivesoftware.smack.XMPPException
Listeners will be preserved from a previous connection if the reconnection occurs after an abrupt termination.
connectInternal in class org.jivesoftware.smack.AbstractXMPPConnectionorg.jivesoftware.smack.XMPPException - if an error occurs while trying to establish the connection.org.jivesoftware.smack.SmackExceptionjava.io.IOExceptionprotected void setWriter(java.io.Writer writer)
writer - protected void afterFeaturesReceived()
throws org.jivesoftware.smack.SmackException.SecurityRequiredException,
org.jivesoftware.smack.SmackException.NotConnectedException
afterFeaturesReceived in class org.jivesoftware.smack.AbstractXMPPConnectionorg.jivesoftware.smack.SmackException.SecurityRequiredExceptionorg.jivesoftware.smack.SmackException.NotConnectedExceptionpublic static void setUseStreamManagementDefault(boolean useSmDefault)
useSmDefault - true to use Stream Management for new connections.public static void setUseStreamManagementResumptiodDefault(boolean useSmResumptionDefault)
useSmResumptionDefault - true to use Stream Management resumption for new connections.public void setUseStreamManagement(boolean useSm)
useSm - true to use Stream Management.public void setUseStreamManagementResumption(boolean useSmResumption)
useSmResumption - true to use Stream Management resumption.public void setPreferredResumptionTime(int resumptionTime)
resumptionTime - the preferred resumption time in secondspublic boolean addRequestAckPredicate(org.jivesoftware.smack.filter.PacketFilter predicate)
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.tcp.sm.predicates package.
If not predicate is configured, the Predicate.forMessagesOrAfter5Stanzas() will be used.
predicate - the predicate to add.public boolean removeRequestAckPredicate(org.jivesoftware.smack.filter.PacketFilter predicate)
predicate - the predicate to remove.public void removeAllRequestAckPredicates()
public void requestSmAcknowledgement()
throws StreamManagementException.StreamManagementNotEnabledException,
org.jivesoftware.smack.SmackException.NotConnectedException
StreamManagementException.StreamManagementNotEnabledException - if Stream Mangement is not enabled.org.jivesoftware.smack.SmackException.NotConnectedException - if the connection is not connected.public void sendSmAcknowledgement()
throws StreamManagementException.StreamManagementNotEnabledException,
org.jivesoftware.smack.SmackException.NotConnectedException
See XEP-198: Stream Management ยง 4. Acks:
"Either party MAY send an 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
StreamManagementException.StreamManagementNotEnabledException - if Stream Management is not enabled.org.jivesoftware.smack.SmackException.NotConnectedException - if the connection is not connected.public void addStanzaAcknowledgedListener(org.jivesoftware.smack.PacketListener listener)
throws StreamManagementException.StreamManagementNotEnabledException
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, PacketListener) when
possible.
listener - the listener to add.StreamManagementException.StreamManagementNotEnabledException - if Stream Management is not enabled.public boolean removeStanzaAcknowledgedListener(org.jivesoftware.smack.PacketListener listener)
listener - the listener.public void removeAllStanzaAcknowledgedListeners()
public org.jivesoftware.smack.PacketListener addStanzaIdAcknowledgedListener(java.lang.String id,
org.jivesoftware.smack.PacketListener listener)
throws StreamManagementException.StreamManagementNotEnabledException
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.
id - the stanza ID.listener - the listener to invoke.StreamManagementException.StreamManagementNotEnabledException - if Stream Management is not enabled.public org.jivesoftware.smack.PacketListener removeStanzaIdAcknowledgedListener(java.lang.String id)
id - the stanza ID.public void removeAllStanzaIdAcknowledgedListeners()
public boolean isSmAvailable()
public boolean isSmEnabled()
public boolean isDisconnectedButSmResumptionPossible()
public boolean isSmResumptionPossible()