/** * Establishes a connection to the XMPP server and performs an automatic login only if the * previous connection state was logged (authenticated). It basically creates and maintains a * socket connection to the server. * * <p> * * <p>Listeners will be preserved from a previous connection if the reconnection occurs after an * abrupt termination. * * @throws 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 appropiate error messages to end-users. */ public void connect() throws XMPPException { // Stablishes the connection, readers and writers connectUsingConfiguration(config); // Automatically makes the login if the user was previouslly connected successfully // to the server and the connection was terminated abruptly if (connected && wasAuthenticated) { // Make the login try { if (isAnonymous()) { // Make the anonymous login loginAnonymously(); } else { login(config.getUsername(), config.getPassword(), config.getResource()); } packetReader.notifyReconnection(); } catch (XMPPException e) { e.printStackTrace(); } } }