@Override public void LogoffUser() { if (connection == null) return; if (connection.isConnected() == true) { connection.disconnect(); } }
@Override protected Boolean doInBackground(String... params) { Log.d(TAG, "Xmpp login task"); jid = params[0]; password = params[1]; Log.d(TAG, "jid " + jid + " server " + server); int port = -1; if (params.length > 2) { server = params[2]; } if (params.length > 3) { if (!TextUtils.isEmpty(params[3])) { port = Integer.parseInt(params[3]); } } Connection connection = prepareConnection(jid, server, port); try { connection.connect(); AccountManager accountManager = new AccountManager(connection); accountManager.createAccount(StringUtils.parseName(jid), password); } catch (XMPPException e) { Log.e(TAG, "Unable to create account", e); exception = e; return false; } finally { connection.disconnect(); } return true; }
@Override public synchronized void disconnect() throws RemoteException { if (isConnected()) { connection.disconnect(); connection = null; } }
@Override public void run() { connection = new XMPPConnection("webmail.1723.org"); try { PacketFilter filter = new FromContainsFilter("webmail.1723.org"); connection.connect(); connection.login("sal", "server", "Server Connection"); connection.addPacketListener(this, filter); while (!done) { Thread.sleep(10000); System.out.println("XMPPModule - Alive"); } connection.disconnect(); } catch (XMPPException e) { System.out.println("XMPP Exception: " + e); } catch (InterruptedException e) { e.printStackTrace(); } }
@Override public void Destroy() { if (connection.isConnected() == true) { connection.disconnect(); } }
/** * Closes the connection by setting presence to unavailable then closing the connection to the * XMPP server. The Connection can still be used for connecting to the server again. * * <p> * * <p>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. */ public void disconnect() { disconnect(new Presence(Presence.Type.unavailable)); }