powered by Jive Software

Should XMPPConnection use Singleton?

Hi guys,

What’‘s the best way to keep a single instance of XMPPConnection? Currently I’‘m using a singleton but it doesn’‘t feel right, mainly because if XMPPConnection is meant to be using Singleton, then the developers could’‘ve done it before, or could’'ve at least provide methods to get a single instance of XMPPConnection?



A singleton sounds like a good method to me, and I’‘m sure the smack developers didn’'t make XMPPConnection a singleton because they meant for people to be able to have as many connections to as many servers as needed.

Right. The framework allows you to have many active connections at the same time so there is no support for singletons. This means that you will need to keep the single connection in your application layer instead of relying on Smack keeping a single connection instance.


– Gato

I’‘m a bit lost (I’‘m new to Jabber/XMPP). May I ask what’'s the use case for multiple XMPPConnections?

Thanks a lot.

Being Smack a library it could be used in different contexts. For instance, you may use Smack in an Application Server and have a connection for each user that is using the website.


– Gato