powered by Jive Software

Connection authenticated events

We are writing a client on top of Smack and find it very useful to be able to tell when the a connection has completed the authentication with the server. Since we support many simultaneous connections we really only want to make the session “real” once it has been authenticated.

To do this we have done defined

public interface ConnectionListener2 extends ConnectionListener {


  • Notification that the connection has been authenticated.


public void connectionAuthenticated();

and updated PacketReader to implement the new interface with


  • Sends out a notification that there was an error with the connection

  • and closes the connection.

  • @param e the exception that causes the connection close event.


void notifyConnectionAuthenticated() {

ArrayList listenersCopy;

synchronized (connectionListeners) {

// Make a copy since it’'s possible that a listener will be removed from the list

listenersCopy = new ArrayList(connectionListeners);

for (Iterator i=listenersCopy.iterator(); i.hasNext(); ) {

ConnectionListener listener = (ConnectionListener)i.next();

if (listener instanceof ConnectionListener2)





This method is called from XMPPConnection.login() and loginAnonymously() just after

authenticated = true.

The change is modest and greatly simplified our user interface.


p.s., I would open a bug/enhancement but can’'t for the life of me figure out how to do so in the bug system.