5

I'm trying to implement a simple jabber messenger on Android using asmack library. Here's the code:

public boolean login()
{
    if (connection != null && connection.isConnected())
    {
        Log.i("XMPP", connection.getHost());
        try 
        {
            connection.login(USERNAME, PASSWORD);
        } 
        catch (XMPPException e) 
        {
            e.printStackTrace();
            return false;
        }
        return true;
    }
    return false;
}

Exception I get after connection.login() (connection looks fine):

service-unavailable(503)
at org.jivesoftware.smack.NonSASLAuthentication.authenticate(NonSASLAuthentication.java:77)
at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:239)
at org.jivesoftware.smack.Connection.login(Connection.java:353)
at com.someapp.networking.XMPPMessenger.login(XMPPMessenger.java:60)
at com.someapp.XMPPService.onCreate(XMPPService.java:33)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2780)
at android.app.ActivityThread.access$3200(ActivityThread.java:119)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1917)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4363)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)

What could be the mistake?

Flow
  • 22,048
  • 13
  • 91
  • 147
Ivan Gromov
  • 3,392
  • 6
  • 36
  • 53
  • Hum could you please add more details? what server are you trying to connect to, are you sure to specify the right port/domain/host? service unavailable generally means that it can' be reached or that you specified wrong information. – Guillaume Jul 16 '11 at 11:02

2 Answers2

1

It's working finally for me by this way :

ConnectionConfiguration connConfig = new ConnectionConfiguration(host,port,host);
connection = new XMPPConnection(connConfig);
connConfig.setSASLAuthenticationEnabled(true); 
connection.connect();
connection.login(userID, password);

I have used Android using Asmack library which I have downloaded from below URL:

https://code.google.com/p/asmack/downloads/detail?name=asmack-2010.05.07.jar

Be careful about the userID.

Instead of using

connection.login("username@ejabberdServerIP",password)

it's work for me only if I use connection.login("username",password);

Good luck...

Min2
  • 9,561
  • 1
  • 17
  • 22
1

Asmack is able to establish a new connection to the server, but it falls into Non-SASL mode for some reason ( The call of NonSASLAuthentication.authenticate(NonSASLAuthentication.java:77) ). I think that's what the server is trying to tell you with the "service-unavailable(503)" response, is that it does not support Non-SASL authentication.

Try to debug why smack does not try SASL authentication.

Note: The lines in the smack source viewer are a bit off because off different versions and the patches from asmack.

Flow
  • 22,048
  • 13
  • 91
  • 147
  • what can be the solution for this, we need to authenticate facebook user and fetch list of friends and send message to them but we cannot loggin as we are getting authentication error – Gopal Rathod Dec 21 '11 at 09:55
  • this is getting after some times as message body ? what could be the issue ? – Chathura Wijesinghe Aug 07 '14 at 14:04