powered by Jive Software

Notification when connection is lost?

There doesn’‘t seem to be any kind of event when the connection to the Jabber server gets severed. How do I know when there is no more connection to the server? It’'s critical to my deployment of the Smack software.

Thanks

John,

Sounds like a good feature to add. Do you have a proposed API?

Regards,

Matt

No idea on the API.

You could have a ConnectionListener class I suppose. Then I could add it to the XMPPConnection, maybe the method would be addConnectionListener.

The ConnectionListener could have a method called connectionLost or disconnected that provided the Exception that was thrown when the Socket read failed from the listener thread.

Thanks for the quick reply Matt.

~ John

John,

This sounds reasonable. Does anyone know how any other libraries have handled this? It might be worth some investigation to see if there other good ideas we can glean.

-Matt

Well I’‘ve developed a few libraries myself, and this is the general structure I used. I just triggered the event after the listener thread’'s while loop has ended. The loop usually ends when an IOException occurs on the underlying socket, or in the case of an XML parser, it just ends normally or throws a parse exception.

BTW, I’‘ll do my best to get this feature into the daily builds by the end of the week. Shouldn’'t be too tough.

Regards,

Matt

FYI, I finally added this feature into CVS today so it will appear in tomorrow’'s build. Comments appreciated!

Thanks,

Matt

You noted that the changes for this feature was added to CVS and would be in the current “build”. Where can I obtain the most recent build. It does not seem to be available in the source zip or tar on the site. Thanks in advance.

Mike,

Sorry about that! I really need to link the daily builds page better from the Smack page. You can find it at:

http://www.jivesoftware.com/xmpp/smack/dailybuilds.jsp

-Matt

Hello,

I have implemented a ConnectionListener in my program. The connectionClosedOnError() method is called just fine when the server is shut down or the connection is otherwise abnormally severed, but connectionClosed() is not called when the close() method on the connection is called. Am I doing something wrong?

Adam,

It looks like my logic was a bit wrong for notfiying the listeners of normal connection closes. I’'ve checked in a fix that should be in the next daily build.

Regards,

Matt