Question

I'm trying to write a simple XMPP application on Android using asmack, but I've encountered a problem that I cannot login to several jabber servers. For example, I can't login into my test Openfire server, although the code works fine with jabber.org accounts.

Login code:

public void login() throws XMPPException
{
    if (connection != null && connection.isConnected())
    {
        try 
        {
            Random generator = new Random();
            int resource_int = generator.nextInt();
            connection.login(USERNAME, PASSWORD, 
                             "Smack_" + Integer.toString(resource_int));
        } 
        catch (XMPPException e) 
        {
            e.printStackTrace();
            connection.disconnect();
            setConnection(null);
            throw e;
        }
        Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.accept_all);
    }
}

As I said, it works with jabber.org, but Openfire returns not-authorized(401) error. How can I fix it?

Was it helpful?

Solution

I never used Openfire, but I'm sure there is a Logfile somewhere - can you post it?

IIRC in Android some security functions (not sure if for SSL or TLS) are not compatible to Smack or Asmack, maybe thats the problem. In this case there is a way to solve it by using an own Socket connection (instead of the included SSL functions of Smack) - To verify this you can port your (XMPP-relevant) code to PC and use the Standard Smack Library.

Another point is, that there are different Smack ports for Android. I personally use the Asmack port from the Beem-project (because the originally Asmack had some issues - but I can't remember which ones...)

But still...without more information I can only guess.

OTHER TIPS

Are you sure that you have the same account and password on the OpenFire server? Try logging into your server using the same username and password with an existing XMPP client. Take Android out of the equation altogether and make sure you can log into both servers first.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top