The org.jivesoftware.smack.XMPPConnection
interface manages your connection to an XMPP server. The default implementation is the org.jivesoftware.smack.tcp.XMPPTCPConnection
class. The class contains three constructors. The simplest, XMPPTCPConnection(CharSequence, String, String)
takes the username, password, and server name you'd like to connect to as arguments. All default connection settings will be used:
XMPPTCPConnection(ConnectionConfiguration)
constructor to specify advanced connection settings. Some of these settings include:Manually specify the server address and port of the server rather than using a DNS SRV lookup.
// Create the configuration for this new connection
XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();
configBuilder.setUsernameAndPassword("username", "password");
configBuilder.setResource("SomeResource");
configBuilder.setXmppDomain("jabber.org");
AbstractXMPPConnection connection = new XMPPTCPConnection(configBuilder.build());
// Connect to the server
connection.connect();
// Log into the server
connection.login();
...
// Disconnect from the server
connection.disconnect();
By default Smack will try to reconnect the connection in case it was abruptly disconnected. The reconnection manager will try to immediately reconnect to the server and increase the delay between attempts as successive reconnections keep failing._
In case you want to force a reconnection while the reconnection manager is waiting for the next reconnection, you can just use AbstractXMPPConnection#connect() and a new attempt will be made. If the manual attempt also failed then the reconnection manager will still continue the reconnection job.
Copyright (C) Jive Software 2002-2008