Checking OpenFire Server for XMPP

I use open fire in my application, but I could not check if my user is connected to the server or not, please suggest me to check.

+5
source share
1 answer

check this method

public XMPPConnection connect(final String username, final String password, final String host, final String service, final String port) { // Create a connection ConnectionConfiguration connConfig = new ConnectionConfiguration(host, Integer.parseInt(port), service); connConfig.setSASLAuthenticationEnabled(false); try { connection = new XMPPConnection(connConfig); connection.connect(); Log.i("XMPPClient", "[SettingsDialog] Connected to " + connection.getHost()); } catch (XMPPException ex) { Log.e("XMPPClient", "[SettingsDialog] Failed to connect to " + connection.getHost()); Log.e("XMPPClient", ex.toString()); } //Login to the server try { connection.login(username, password, "Smack" + new Date().getTime()); Log.i("XMPPClient", "Logged in as " + connection.getUser()); Presence presence = new Presence(Presence.Type.available);// Set the presence to available connection.sendPacket(presence); } catch (XMPPException ex) { Log.e("XMPPClient", "[SettingsDialog] Failed to log in as " + username); Log.e("XMPPClient", ex.toString()); return null; } //initialize(); initialize();//Add packet listener on connection for listen any message received return connection; } 

this connection object will help you find your user or not.

-1
source

Source: https://habr.com/ru/post/1240407/


All Articles