|
Smack | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jivesoftware.smack.Connection org.jivesoftware.smack.XMPPConnection
public class XMPPConnection
Creates a socket connection to a XMPP server. This is the default connection to a Jabber server and is specified in the XMPP Core (RFC 3920).
Connection
Nested Class Summary |
---|
Nested classes/interfaces inherited from class org.jivesoftware.smack.Connection |
---|
Connection.InterceptorWrapper, Connection.ListenerWrapper |
Field Summary |
---|
Fields inherited from class org.jivesoftware.smack.Connection |
---|
collectors, compressionHandler, compressionHandlers, config, connectionCounterValue, connectionListeners, DEBUG_ENABLED, debugger, interceptors, reader, recvListeners, saslAuthentication, sendListeners, writer |
Constructor Summary | |
---|---|
XMPPConnection(ConnectionConfiguration config)
Creates a new XMPP connection in the same way XMPPConnection(ConnectionConfiguration,CallbackHandler) does, but
with no callback handler for password prompting of the keystore. |
|
XMPPConnection(ConnectionConfiguration config,
javax.security.auth.callback.CallbackHandler callbackHandler)
Creates a new XMPP connection using the specified connection configuration. |
|
XMPPConnection(String serviceName)
Creates a new XMPP connection in the same way XMPPConnection(String,CallbackHandler) does, but
with no callback handler for password prompting of the keystore. |
|
XMPPConnection(String serviceName,
javax.security.auth.callback.CallbackHandler callbackHandler)
Creates a new connection to the specified XMPP server. |
Method Summary | |
---|---|
void |
addPacketWriterInterceptor(PacketInterceptor packetInterceptor,
PacketFilter packetFilter)
Deprecated. replaced by Connection.addPacketInterceptor(PacketInterceptor, PacketFilter) . |
void |
addPacketWriterListener(PacketListener packetListener,
PacketFilter packetFilter)
Deprecated. replaced by Connection.addPacketSendingListener(PacketListener, PacketFilter) . |
void |
connect()
Establishes a connection to the XMPP server and performs an automatic login only if the previous connection state was logged (authenticated). |
void |
disconnect(Presence unavailablePresence)
Closes the connection. |
String |
getConnectionID()
Returns the connection ID for this connection, which is the value set by the server when opening a XMPP stream. |
ParsingExceptionCallback |
getParsingExceptionCallback()
Get the current active parsing exception callback. |
Roster |
getRoster()
Returns the roster for the user. |
String |
getUser()
Returns the full XMPP address of the user that is logged in to the connection or null if not logged in yet. |
boolean |
isAnonymous()
Returns true if currently authenticated anonymously. |
boolean |
isAuthenticated()
Returns true if currently authenticated by successfully calling the login method. |
boolean |
isConnected()
Returns true if currently connected to the XMPP server. |
boolean |
isSecureConnection()
Returns true if the connection to the server has successfully negotiated encryption. |
boolean |
isSocketClosed()
|
boolean |
isUsingCompression()
Returns true if network traffic is being compressed. |
boolean |
isUsingTLS()
Returns true if the connection to the server has successfully negotiated TLS. |
void |
login(String username,
String password,
String resource)
Logs in to the server using the strongest authentication mode supported by the server, then sets presence to available. |
void |
loginAnonymously()
Logs in to the server anonymously. |
protected void |
notifyReconnection()
Sends a notification indicating that the connection was reconnected successfully. |
void |
removePacketWriterInterceptor(PacketInterceptor packetInterceptor)
Deprecated. replaced by Connection.removePacketInterceptor(PacketInterceptor) . |
void |
removePacketWriterListener(PacketListener packetListener)
Deprecated. replaced by Connection.removePacketSendingListener(PacketListener) . |
void |
sendPacket(Packet packet)
Sends the specified packet to the server. |
void |
setParsingExceptionCallback(ParsingExceptionCallback callback)
Install a parsing exception callback, which will be invoked once an exception is encountered while parsing a stanza |
protected void |
shutdown(Presence unavailablePresence)
Closes the connection by setting presence to unavailable then closing the stream to the XMPP server. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public XMPPConnection(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
XMPPConnection(ConnectionConfiguration)
constructor.Note that XMPPConnection constructors do not establish a connection to the server and you must call
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 XMPPConnection(String serviceName)
XMPPConnection(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 XMPPConnection(ConnectionConfiguration config)
XMPPConnection(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 XMPPConnection(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
XMPPConnection(String)
constructor is a better approach.Note that XMPPConnection constructors do not establish a connection to the server and you must call
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.Method Detail |
---|
public String getConnectionID()
Connection
getConnectionID
in class Connection
public String getUser()
Connection
getUser
in class Connection
public void setParsingExceptionCallback(ParsingExceptionCallback callback)
callback
- the callback to installpublic ParsingExceptionCallback getParsingExceptionCallback()
public void login(String username, String password, String resource) throws XMPPException
Connection
Before logging in (i.e. authenticate) to the server the connection must be connected.
It is possible to log in without sending an initial available presence by using
ConnectionConfiguration.setSendPresence(boolean)
. If this connection is
not interested in loading its roster upon login then use
ConnectionConfiguration.setRosterLoadedAtLogin(boolean)
.
Finally, if you want to not pass a password and instead use a more advanced mechanism
while using SASL then you may be interested in using
ConnectionConfiguration.setCallbackHandler(javax.security.auth.callback.CallbackHandler)
.
For more advanced login settings see ConnectionConfiguration
.
login
in class Connection
username
- the username.password
- the password or null if using a CallbackHandler.resource
- the resource.
XMPPException
- if an error occurs.public void loginAnonymously() throws XMPPException
Connection
loginAnonymously
in class Connection
XMPPException
- if an error occurs or anonymous logins are not supported by the server.public Roster getRoster()
Connection
This method will never return null
, instead if the user has not yet logged into
the server or is logged in anonymously all modifying methods of the returned roster object
like Roster.createEntry(String, String, String[])
,
Roster.removeEntry(RosterEntry)
, etc. except adding or removing
RosterListener
s will throw an IllegalStateException.
getRoster
in class Connection
public boolean isConnected()
Connection
isConnected
in class Connection
public boolean isSecureConnection()
Connection
isSecureConnection
in class Connection
public boolean isSocketClosed()
public boolean isAuthenticated()
Connection
isAuthenticated
in class Connection
public boolean isAnonymous()
Connection
isAnonymous
in class Connection
protected void shutdown(Presence unavailablePresence)
Connection.disconnect()
the connection's
packet reader, packet writer, and Roster
will not be removed; thus
connection's state is kept.
unavailablePresence
- the presence packet to send during shutdown.public void disconnect(Presence unavailablePresence)
Connection
This method cleans up all resources used by the connection. Therefore, the roster, listeners and other stateful objects cannot be re-used by simply calling connect() on this connection again. This is unlike the behavior during unexpected disconnects (and subsequent connections). In that case, all state is preserved to allow for more seamless error recovery.
disconnect
in class Connection
unavailablePresence
- the presence packet to send during shutdown.public void sendPacket(Packet packet)
Connection
sendPacket
in class Connection
packet
- the packet to send.public void addPacketWriterInterceptor(PacketInterceptor packetInterceptor, PacketFilter packetFilter)
Connection.addPacketInterceptor(PacketInterceptor, PacketFilter)
.
packetInterceptor
- the packet interceptor to notify of packets about to be sent.packetFilter
- the packet filter to use.public void removePacketWriterInterceptor(PacketInterceptor packetInterceptor)
Connection.removePacketInterceptor(PacketInterceptor)
.
packetInterceptor
- the packet interceptor to remove.public void addPacketWriterListener(PacketListener packetListener, PacketFilter packetFilter)
Connection.addPacketSendingListener(PacketListener, PacketFilter)
.
packetListener
- the packet listener to notify of sent packets.packetFilter
- the packet filter to use.public void removePacketWriterListener(PacketListener packetListener)
Connection.removePacketSendingListener(PacketListener)
.
packetListener
- the packet listener to remove.public boolean isUsingTLS()
public boolean isUsingCompression()
Connection
isUsingCompression
in class Connection
public void connect() throws XMPPException
Listeners will be preserved from a previous connection if the reconnection occurs after an abrupt termination.
connect
in class Connection
XMPPException
- if an error occurs while trying to establish the connection.
Two possible errors can occur which will be wrapped by an XMPPException --
UnknownHostException (XMPP error code 504), and IOException (XMPP error code
502). The error codes and wrapped exceptions can be used to present more
appropriate error messages to end-users.protected void notifyReconnection()
|
Smack | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |