1

public void connect() {

    final ProgressDialog dialog = ProgressDialog.show(this,"Connecting...", "Please wait...", false);

    Thread t = new Thread(new Runnable() {



        @Override
        public void run() {
            // Create a connection
            ConnectionConfiguration connConfig = new ConnectionConfiguration(
                    HOST, PORT,SERVICE);
            XMPPConnection connection = new XMPPConnection(connConfig);

            try {
                connection.connect();
                Log.i("XMPPChatDemoActivity",
                        "Connected to " + connection.getHost());
            } catch (XMPPException ex) 
            {
                Log.e("XMPPChatDemoActivity", "Failed to connect to "
                        + connection.getHost());
                Log.e("XMPPChatDemoActivity", ex.toString());
                setConnection(null);
            }




            try {
            //  SASLAuthentication.supportSASLMechanism("PLAIN", 0);
                connection.login(username, password);
                Log.i("XMPPChatDemoActivity","Logged in as " + connection.getUser());

                // Set the status to available
                Presence presence = new Presence(Presence.Type.available);
                connection.sendPacket(presence);
                setConnection(connection);

                Roster roster = connection.getRoster();
                Collection<RosterEntry> entries = roster.getEntries();
                for (RosterEntry entry : entries) {
                    Log.d("XMPPChatDemoActivity",
                            "--------------------------------------");
                    Log.d("XMPPChatDemoActivity", "RosterEntry " + entry);
                    Log.d("XMPPChatDemoActivity",
                            "User: " + entry.getUser());
                    Log.d("XMPPChatDemoActivity",
                            "Name: " + entry.getName());
                    Log.d("XMPPChatDemoActivity",
                            "Status: " + entry.getStatus());
                    Log.d("XMPPChatDemoActivity",
                            "Type: " + entry.getType());
                    Presence entryPresence = roster.getPresence(entry
                            .getUser());

                    Log.d("XMPPChatDemoActivity", "Presence Status: "
                            + entryPresence.getStatus());
                    Log.d("XMPPChatDemoActivity", "Presence Type: "+ entryPresence.getType());
                    Presence.Type type = entryPresence.getType();
                    if (type == Presence.Type.available)
                        Log.d("XMPPChatDemoActivity", "Presence AVIALABLE");
                    Log.d("XMPPChatDemoActivity", "Presence : "+ entryPresence);

                }
            } catch (XMPPException ex) {
                Log.e("XMPPChatDemoActivity", "Failed to log in as "
                        + username);
                Log.e("XMPPChatDemoActivity", ex.toString());
                setConnection(null);
            }



            dialog.dismiss();
        }
    });
    t.start();
    dialog.show();
}

} i have created the new user the new user is been created sucessfully but when i am logging with tht username and password but its giving me error while loging giving me the following error. 03-12 07:10:58.495: E/XMPPChatDemoActivity(13411): SASL authentication failed using mechanism DIGEST-MD5:

and i am using the port : 5222

2 Answers2

1

try this

    private XMPPConnection xmppConnection = null;

    private void setConfiguration() {
    ConnectionConfiguration config = new ConnectionConfiguration(IP_address,
            PORT); // ip address of your server and port is 5222
    SmackConfiguration.setPacketReplyTimeout(Config.PACKET_TIME_OUT);
    System.out.println(SmackConfiguration.getVersion());
    config.setRosterLoadedAtLogin(true);
    config.setSendPresence(true);
    config.setSASLAuthenticationEnabled(true);
    // config.setCompressionEnabled(true);
    config.setVerifyChainEnabled(false);
    config.setReconnectionAllowed(true);
    xmppConnection = new XMPPConnection(config);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        config.setTruststoreType("AndroidCAStore");
        config.setTruststorePassword(null);
        config.setTruststorePath(null);
    } else {
        config.setTruststoreType("BKS");
        String path = System.getProperty("javax.net.ssl.trustStore");
        if (path == null)
            path = System.getProperty("java.home") + File.separator + "etc"
                    + File.separator + "security" + File.separator
                    + "cacerts.bks";
        config.setTruststorePath(path);
    }


xmppConnection.connect();
xmppConnection.login(username,password);
}
Yograj Shinde
  • 839
  • 12
  • 23
0
       ConnectionConfiguration cc = new ConnectionConfiguration(domain,
                port, service);
        // SASLAuthentication.supportSASLMechanism("PLAIN", 0);
        cc.setSASLAuthenticationEnabled(false);
        cc.setRosterLoadedAtLogin(true);
        cc.setCompressionEnabled(false);
        cc.setReconnectionAllowed(true);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            cc.setTruststoreType("AndroidCAStore");
            cc.setTruststorePassword(null);
            cc.setTruststorePath(null);
        } else {
            cc.setTruststoreType("BKS");
            String path = System.getProperty("javax.net.ssl.trustStore");
            if (path == null) {
                path = System.getProperty("java.home") + File.separator
                        + "etc" + File.separator + "security"
                        + File.separator + "cacerts.bks";
            }
            cc.setTruststorePath(path);
        }
   XMPPConnection connection = new XMPPConnection(cc);
   connection.login(username, password);

Try this code.You need to disable SASL authentication in case client might not support it.So this line will do the trick for you.

 cc.setSASLAuthenticationEnabled(false);

Hope it will help.

Nirav Tukadiya
  • 3,367
  • 1
  • 18
  • 36