Asmack 503 error

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?

Hi Ivan,

Have you try to call :

ConnectionConfiguration config = new ConnectionConfiguration(SERVER_HOST, SERVER_PORT, SERVICE_NAME);

XMPPConnection xmppConnection = new XMPPConnection(config);

xmppConnection.connect();

before trying to do a

connection.login(USERNAME, PASSWORD);

if you do, try to remove the server extension from the USERNAME.

ex: if your username is " toto@yourserver.com ", just type "toto"instead

Thanks for the answer!

I’ve called xmppConnection.connect() and it works properly (isConnected() returns true).

Removing server extension also didn’t help.

If it would be helpful, full source is avaliable at http://pastebin.com/index/U3k1RHSH

Hum, ok, i’ve take a look at the source code and I see you plan to log on talk.google.com and others jabber servers.

When you log on gmail you need a full login ( with the server extension @gmail.com ) and on others server you should remove the server extension. (There is a utility in smack to do that “StringUtils.parseName(LOGIN);”).

you can look at http://oneminutedistraction.wordpress.com/2010/07/26/discovering-services/ for that.

for your problem, try to remove the config options like

config.setSASLAuthenticationEnabled(false);

config.setSecurityMode(SecurityMode.disabled);

I have not set that options and I can log in on talk.google.com and others jabbers servers well with asmack.

youcan also try to put the aSmack debugger on:

Writer wrt = new Writer() {

@Override

public void write(char[] buf, int offset, int count) throws IOException {

// TODO Auto-generated method stub

}

@Override

public void flush() throws IOException {

}

@Override

public void close() throws IOException {

// TODO Auto-generated method stub

}

};

Reader read = new Reader() {

@Override

public int read(char[] buf, int offset, int count) throws IOException {

// TODO Auto-generated method stub

return 0;

}

@Override

public void close() throws IOException {

// TODO Auto-generated method stub

}

};

//Enable debug

config.setDebuggerEnabled(true);

Connection.DEBUG_ENABLED = true;

new AndroidDebugger(xmppConnection, wrt, read);

This will log all packet sent and received on the logcat as “SMACK” (you can see it on DDMS). Maybe you will see something relevant about your error.

btw, what version of aSmack are you using ? try http://code.google.com/p/asmack/downloads/detail?name=asmack-2010.05.07.jar

this is the last version on the google code, witch is a litle bit old i know, but it works well for me !

Good Luck